post_comments_feed_link()
云策文档标注
概述
post_comments_feed_link() 函数用于输出文章的评论订阅链接,支持自定义链接文本、文章ID和订阅类型,并包含一个过滤器钩子用于修改链接HTML。
关键要点
- 函数输出文章的评论订阅链接,链接文本可自定义,默认为“Comments Feed”。
- 参数包括可选的 $link_text(链接文本)、$post_id(文章ID,默认为全局 $post 的ID)和 $feed(订阅类型,如 'rss2' 或 'atom',默认为 get_default_feed() 的值)。
- 内部使用 get_post_comments_feed_link() 获取链接URL,并通过 apply_filters() 应用 post_comments_feed_link_html 过滤器。
- 相关函数包括 get_post_comments_feed_link()、__()、esc_url() 和 apply_filters()。
- 自 WordPress 2.5.0 版本引入。
代码示例
function post_comments_feed_link( $link_text = '', $post_id = 0, $feed = '' ) {
$url = get_post_comments_feed_link( $post_id, $feed );
if ( empty( $link_text ) ) {
$link_text = __( 'Comments Feed' );
}
$link = '' . $link_text . '';
/**
* Filters the post comment feed link anchor tag.
*
* @since 2.8.0
*
* @param string $link The complete anchor tag for the comment feed link.
* @param int $post_id Post ID.
* @param string $feed The feed type. Possible values include 'rss2', 'atom',
* or an empty string for the default feed type.
*/
echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed );
}
原文内容
Displays the comment feed link for a post.
Description
Prints out the comment feed link for a post. Link text is placed in the anchor. If no link text is specified, default text is used. If no post ID is specified, the current post is used.
Parameters
$link_textstringoptional-
Descriptive link text. Default ‘Comments Feed’.
$post_idintoptional-
Post ID. Default is the ID of the global
$post. $feedstringoptional-
Feed type. Possible values include
'rss2','atom'.
Default is the value of get_default_feed() .
Source
function post_comments_feed_link( $link_text = '', $post_id = 0, $feed = '' ) {
$url = get_post_comments_feed_link( $post_id, $feed );
if ( empty( $link_text ) ) {
$link_text = __( 'Comments Feed' );
}
$link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>';
/**
* Filters the post comment feed link anchor tag.
*
* @since 2.8.0
*
* @param string $link The complete anchor tag for the comment feed link.
* @param int $post_id Post ID.
* @param string $feed The feed type. Possible values include 'rss2', 'atom',
* or an empty string for the default feed type.
*/
echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed );
}
Hooks
- apply_filters( ‘post_comments_feed_link_html’, string $link, int $post_id, string $feed )
-
Filters the post comment feed link anchor tag.
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |