get_the_category_rss()
get_the_category_rss( string $type = null ) 检索所有文章类别,格式…
get_the_category_rss( string $type = null )
检索所有文章类别,格式化后用于提要。
Retrieve all of the post categories, formatted for use in feeds.
目录锚点:#说明#参数#返回#源码
说明(Description)
feed循环中当前post的所有类别都将被检索并添加feed标记,以便可以轻松地将它们添加到RSS2、Atom或RSS1和RSS0.91 RDF feed中。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$type | (string) | 可选 | default是get_default_feed()返回的类型。 |
返回(Return)
(string)要在提要中显示的所有文章类别。
源码(Source)
/** * 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 ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
2.1.0 | wp-includes/feed.php:375 | 1 function | 9 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!