检索当前帖子评论的链接。
原型
get_comments_link( int|WP_Post $post_id )
参数
$post_id
(int|WP_Post)
(Optional)
发布ID或WP_Post对象。默认为全球$ post。
返回值
(string)
评论的链接。
源文件
路径:wp-includes/comment-template.php
<?php
...
function get_comments_link( $post_id = 0 ) {
$hash = get_comments_number( $post_id ) ? '#comments' : '#respond';
$comments_link = get_permalink( $post_id ) . $hash;
/**
* Filters the returned post comments permalink.
*
* @since 3.6.0
*
* @param string $comments_link Post comments permalink with '#comments' appended.
* @param int|WP_Post $post_id Post ID or WP_Post object.
*/
return apply_filters( 'get_comments_link', $comments_link, $post_id );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_comments_link/