rss_enclosure

函式
rss_enclosure ( No parameters )

rss_enclosure: 這是一個WordPress函式,為一個給定的URL生成一個RSS外殼標籤。RSS外殼用於將一個檔案與一個RSS提要專案聯絡起來,允許讀者直接從提要中下載和檢視該檔案。rss_enclosure函式為外殼生成必要的XML標籤。

顯示當前文章的rss enclosure。

使用全域性$post來檢查該文章是否需要密碼,以及使用者是否有該文章的密碼。如果沒有,那麼它將在顯示之前返回。

也使用函式get_post_custom()來獲取文章的’enclosure’後設資料欄位,並解析其值來顯示enclosure(s)。圍欄由帶有URI和其他屬性的圍欄HTML標籤組成。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rss_enclosure() {
if ( post_password_required() ) {
return;
}
foreach ( (array) get_post_custom() as $key => $val ) {
if ( 'enclosure' === $key ) {
foreach ( (array) $val as $enc ) {
$enclosure = explode( "n", $enc );
// Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'.
$t = preg_split( '/[ t]/', trim( $enclosure[2] ) );
$type = $t[0];
/**
* Filters the RSS enclosure HTML link tag for the current post.
*
* @since 2.2.0
*
* @param string $html_link_tag The HTML link tag with a URI and other attributes.
*/
echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "n" );
}
}
}
}
function rss_enclosure() { if ( post_password_required() ) { return; } foreach ( (array) get_post_custom() as $key => $val ) { if ( 'enclosure' === $key ) { foreach ( (array) $val as $enc ) { $enclosure = explode( "n", $enc ); // Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'. $t = preg_split( '/[ t]/', trim( $enclosure[2] ) ); $type = $t[0]; /** * Filters the RSS enclosure HTML link tag for the current post. * * @since 2.2.0 * * @param string $html_link_tag The HTML link tag with a URI and other attributes. */ echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "n" ); } } } }
function rss_enclosure() {
	if ( post_password_required() ) {
		return;
	}

	foreach ( (array) get_post_custom() as $key => $val ) {
		if ( 'enclosure' === $key ) {
			foreach ( (array) $val as $enc ) {
				$enclosure = explode( "n", $enc );

				// Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'.
				$t    = preg_split( '/[ t]/', trim( $enclosure[2] ) );
				$type = $t[0];

				/**
				 * Filters the RSS enclosure HTML link tag for the current post.
				 *
				 * @since 2.2.0
				 *
				 * @param string $html_link_tag The HTML link tag with a URI and other attributes.
				 */
				echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "n" );
			}
		}
	}
}

常見問題

FAQs
檢視更多 >