返回介绍

get_the_category_rss()

发布于 2017-09-11 00:33:13 字数 3320 浏览 1189 评论 0 收藏 0

get_the_category_rss( string $type = null )

Retrieve all of the post categories, formatted for use in feeds.


description

All of the categories for the current post in the feed loop, will be retrieved and have feed markup added, so that they can easily be added to the RSS2, Atom, or RSS1 and RSS0.91 RDF feeds.


参数

$type

(string) (Optional) default is the type returned by get_default_feed().

Default value: null


返回值

(string) All of the post categories for displaying in the feed.


源代码

File: wp-includes/feed.php

function get_the_category_rss($type = null) {
	if ( empty($type) )
		$type = get_default_feed();
	$categories = get_the_category();
	$tags = get_the_tags();
	$the_list = '';
	$cat_names = array();

	$filter = 'rss';
	if ( 'atom' == $type )
		$filter = 'raw';

	if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
		$cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
	}

	if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
		$cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
	}

	$cat_names = array_unique($cat_names);

	foreach ( $cat_names as $cat_name ) {
		if ( 'rdf' == $type )
			$the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
		elseif ( 'atom' == $type )
			$the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) );
		else
			$the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";
	}

	/**
	 * Filters all of the post categories for display in a feed.
	 *
	 * @since 1.2.0
	 *
	 * @param string $the_list All of the RSS post categories.
	 * @param string $type     Type of feed. Possible values include 'rss2', 'atom'.
	 *                         Default 'rss2'.
	 */
	return apply_filters( 'the_category_rss', $the_list, $type );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/category-template.php: get_the_tags()
  • wp-includes/category-template.php: get_the_category()
  • wp-includes/formatting.php: esc_attr()
  • wp-includes/taxonomy.php: sanitize_term_field()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/feed.php: the_category_rss
  • wp-includes/feed.php: get_default_feed()
  • wp-includes/feed.php: get_bloginfo_rss()
  • wp-includes/option.php: get_option()
  • Show 4 more uses Hide more uses

Used By

  • wp-includes/feed.php: the_category_rss()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文