get_post_comments_feed_link()获取文章评论的Feed订阅网址

目录

描述

译文

检索文章评论feed的永久链接

原文

Retrieve the permalink for the post comments feed.

get_post_comments_feed_link() 描述

用法

<?php get_post_comments_feed_link$post_id$feed ?>

get_post_comments_feed_link() 用法

参数

$post_id

(integer) (可选) Post ID.

默认值: ''

$feed

(string) (可选) Feed type.

默认值: ''

get_post_comments_feed_link() 参数

返回值

(string) 

get_post_comments_feed_link() 返回值

注意

  • 使用到 global: (integer) $id

get_post_comments_feed_link() 注意

历史

添加于 版本: 2.2.0

get_post_comments_feed_link() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID.
 * @param string $feed    Optional. Feed type.
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '') {
	$post_id = absint( $post_id );

	if ( ! $post_id )
		$post_id = get_the_ID();

	if ( empty( $feed ) )
		$feed = get_default_feed();

	if ( '' != get_option('permalink_structure') ) {
		if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
			$url = _get_page_link( $post_id );
		else
			$url = get_permalink($post_id);

		$url = trailingslashit($url) . 'feed';
		if ( $feed != get_default_feed() )
			$url .= "/$feed";
		$url = user_trailingslashit($url, 'single_feed');
	} else {
		$type = get_post_field('post_type', $post_id);
		if ( 'page' == $type )
			$url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
		else
			$url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
	}

	/**
	 * Filter the post comments feed permalink.
	 *
	 * @since 1.5.1
	 *
	 * @param string $url Post comments feed permalink.
	 */
	return apply_filters( 'post_comments_feed_link', $url );
}

get_post_comments_feed_link() 源文件