rss_enclosure()获取当前文章的Feed

目录

描述

译文

显示当前文章的rss enclosure。

使用全局变量$post来检查文章是否要求密码,以及用户是否具有文章的密码。若没有密码则返回之前页面。

用get_post_custom() 函数获取文章的'enclosure' metadata字段,解析该值并显示enclosure。Enclosure由一个带有URI的enclosure HTML标签和其他属性组成。

原文

Display the rss enclosure for the current post.

Uses the global $post to check whether the post requires a password and if the user has the password for the post. If not then it will return before displaying.

Also uses the function get_post_custom() to get the post's 'enclosure' metadata field and parses the value to display the enclosure(s). The enclosure(s) consist of enclosure HTML tag(s) with a URI and other attributes.

rss_enclosure() 描述

用法

<?php rss_enclosure() ?>

rss_enclosure() 用法

参数

None.

rss_enclosure() 参数

返回值

(void) 

This function does not return a value.

rss_enclosure() 返回值

注意

rss_enclosure() 注意

历史

添加于 版本: 1.5.0

rss_enclosure() 历史

源文件

rss_enclosure() 函数的代码位于 wp-includes/feed.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Display the rss enclosure for the current post.
 *
 * Uses the global $post to check whether the post requires a password and if
 * the user has the password for the post. If not then it will return before
 * displaying.
 *
 * Also uses the function get_post_custom() to get the post's 'enclosure'
 * metadata field and parses the value to display the enclosure(s). The
 * enclosure(s) consist of enclosure HTML tag(s) with a URI and other
 * attributes.
 *
 * @since 1.5.0
 */
function rss_enclosure() {
	if ( post_password_required() )
		return;

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

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

				/**
				 * Filter 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', '' . "
" );
			}
		}
	}
}

rss_enclosure() 源文件