下面是如何在rss提要中显示分类术语。只需将其添加到函数中即可。php文件并更新$tax
和$post_type
符合您需求的变量:
add_filter(\'the_category_rss\', \'wpq_the_category_rss\');
add_filter(\'rss2_ns\', \'wpq_rss2_ns\');
function wpq_the_category_rss($the_list_original)
{
$tax = \'announcement_tags\';
$post_type = \'announcements\';
if(get_post_type() != $post_type)
return $the_list;
$categories = get_the_terms(get_the_ID(), $tax);
$the_list = \'\';
$cat_names = array();
if(!empty($categories))
{
foreach((array)$categories as $category)
{
$cat_names[] = sanitize_term_field(\'name\', $category->name, $category->term_id, $tax, \'rss\');
$cat_descriptions[] = sanitize_term_field(\'description\', $category->description, $category->term_id, $tax, \'rss\');
}
}
$cat_names = array_unique($cat_names);
$cat_descriptions = array_unique($cat_descriptions);
foreach($cat_names as $cat_name)
{
$the_list .= "\\t\\t<category domain=\\"". $tax ."\\"><![CDATA[" . @html_entity_decode($cat_name, ENT_COMPAT, get_option(\'blog_charset\') ) . "]]></category>\\n";
}
foreach($cat_descriptions as $cat_description)
{
$the_list .= "\\t\\t<wpq:category_description domain=\\"". $tax ."\\"><![CDATA[". @html_entity_decode($cat_description, ENT_COMPAT, get_option(\'blog_charset\')) ."]]></wpq:category_description>\\n";
}
return $the_list_original.$the_list;
}