get_the_category_rss()获取所有的分类Feed订阅信息

目录

描述

译文

检索所有文章类别,并格式化以便在feed中使用。

feed循环中当前文章的所有类别都将被检索,并添加feed markup,这样这些类别就可以被添加到RSS2, Atom, or RSS1 和RSS0.91 RDF feeds中。

原文

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

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.

get_the_category_rss() 描述

用法

<?php get_the_category_rss$type ); ?>

get_the_category_rss() 用法

参数

$type

(string) (可选) default is 'rss'. Either 'rss', 'atom', or 'rdf'.

默认值: 'rss'

get_the_category_rss() 参数

返回值

(string) 

All of the post categories for displaying in the feed.

get_the_category_rss() 返回值

注意

历史

添加于 版本: 2.1.0

get_the_category_rss() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve all of the post categories, formatted for use in feeds.
 *
 * 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.
 *
 * @since 2.1.0
 *
 * @param string $type Optional, default is the type returned by get_default_feed().
 * @return string All of the post categories for displaying in the feed.
 */
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 .= "		
";
		elseif ( 'atom' == $type )
			$the_list .= sprintf( '', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) );
		else
			$the_list .= "		
";
	}

	/**
	 * Filter 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 );
}

get_the_category_rss() 源文件