get_category_feed_link()获取一个分类的Feed订阅链接

目录

描述

译文

该函数自2.5版启用,返回指定类别中所有文章的feed链接。可请求特别feed,但为空时,函数返回'rss2'feed链接。该函数取代了已经弃用的get_category_rss_link函数。

原文

This function returns a link to the feed for all posts in the specified category. A particular feed can be requested, but if the feed parameter is left blank, it returns the 'rss2' feed link.

get_category_feed_link() 描述

用法

 <?php get_category_feed_link$cat_id$feed ); ?> 

Parameters

$cat_id

(string) (required) Category ID of feed link to return.

Default: None

$feed

(string) (optional) Type of feed, accepts 'rss2' or 'atom'.

Default: rss2

get_category_feed_link() 用法

示例

Return the rss2 feed link for post in category 2

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php get_category_feed_link('2', ''); ?>

Display an rss link automatically when viewing a category. Insert this code on the category.php or archive.php page template.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

if ( is_category() ) {

    $category = get_category( get_query_var('cat') );

    if ( ! empty( $category ) )
        echo '<div class="category-feed"><a href="' . get_category_feed_link( $category->cat_ID ) . '" title="' . sprintf( __( 'Subscribe to this category', 'appthemes' ), $category->name ) . '" rel="nofollow">' . __( 'Subscribe!', 'appthemes' ) . '</a></div>';

}

get_category_feed_link() 示例

历史

  • 添加于 版本: 2.5.0
  • This function replaces the deprecated get_category_rss_link function.

get_category_feed_link() 历史

源文件

get_category_feed_link() 函数的代码位于 wp-includes/link-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the feed link for a category.
 *
 * Returns a link to the feed for all posts in a given category. A specific feed
 * can be requested or left blank to get the default feed.
 *
 * @since 2.5.0
 *
 * @param int    $cat_id ID of a category.
 * @param string $feed   Optional. Feed type.
 * @return string Link to the feed for the category specified by $cat_id.
*/
function get_category_feed_link( $cat_id, $feed = '' ) {
	return get_term_feed_link( $cat_id, 'category', $feed );
}

get_category_feed_link() 源文件

相关