检索格式化以在Feed中使用的所有帖子类别。

原型

get_the_category_rss( string $type = null )

描述

将检索Feed循环中当前帖子的所有类别并添加提要标记,以便可以轻松地将它们添加到RSS2,Atom或RSS1和RSS0.91 RDF提要中。

参数

$type (string) (Optional)  default是get_default_feed()返回的类型。

返回值

(string)  用于在Feed中显示的所有帖子类别。

源文件

路径:wp-includes/feed.php

<?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 .= "tt<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 .= "tt<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 );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_the_category_rss/