get_comments_link

函式
get_comments_link ( $post = 0 )
引數
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global $post.
    Required:
返回值
  • (string) The link to the comments.
定義位置
相關方法
get_comment_linknext_comments_linkedit_comment_linkcomments_linkget_next_comments_link
引入
1.5.0
棄用
-

get_comments_link: 這個函式用來生成一個特定的文章或頁面的評論區的連結。它返回帶有”x Comments”或”Leave a Comment”文字的HTML連結。

檢索當前文章評論的連結。

function get_comments_link( $post = 0 ) {
	$hash          = get_comments_number( $post ) ? '#comments' : '#respond';
	$comments_link = get_permalink( $post ) . $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          Post ID or WP_Post object.
	 */
	return apply_filters( 'get_comments_link', $comments_link, $post );
}

常見問題

FAQs
檢視更多 >