get_the_category_rss
函数
get_the_category_rss ( $type = null )
- 参数
-
-
(string)
$type
Optional, default is the type returned by get_default_feed().- Required: 否
- Default: null
-
(string)
- 返回值
-
- (string) All of the post categories for displaying in the feed.
- 定义位置
-
-
wp-includes/feed.php
, line 379
-
wp-includes/feed.php
- 引入
- 2.1.0
- 弃用
- –
检索所有的文章类别,并将其格式化以用于feeds。
在feed循环中,当前帖子的所有类别都将被检索到,并添加了feed标记,因此它们可以很容易地被添加到RSS2、Atom、或RSS1和RSS0.91 RDF feeds。
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 .= "ttn"; } elseif ( 'atom' === $type ) { $the_list .= sprintf( ' ', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); } else { $the_list .= "tt 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 ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。