get_comments_number

函式
get_comments_number ( $post = 0 )
引數
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is the global `$post`.
    Required:
返回值
  • (string|int) If the post exists, a numeric string representing the number of comments the post has, otherwise 0.
定義位置
相關方法
get_comments_number_textcomments_numberget_comment_metaget_comment_timeget_comments_link
引入
1.5.0
棄用
-

get_comments_number: 這個函式用來檢索一個文章或頁面的評論總數。它返回的是整數值。

檢索一個文章的評論數量。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_comments_number( $post = 0 ) {
$post = get_post( $post );
$count = $post ? $post->comment_count : 0;
$post_id = $post ? $post->ID : 0;
/**
* Filters the returned comment count for a post.
*
* @since 1.5.0
*
* @param string|int $count A string representing the number of comments a post has, otherwise 0.
* @param int $post_id Post ID.
*/
return apply_filters( 'get_comments_number', $count, $post_id );
}
function get_comments_number( $post = 0 ) { $post = get_post( $post ); $count = $post ? $post->comment_count : 0; $post_id = $post ? $post->ID : 0; /** * Filters the returned comment count for a post. * * @since 1.5.0 * * @param string|int $count A string representing the number of comments a post has, otherwise 0. * @param int $post_id Post ID. */ return apply_filters( 'get_comments_number', $count, $post_id ); }
function get_comments_number( $post = 0 ) {
	$post = get_post( $post );

	$count   = $post ? $post->comment_count : 0;
	$post_id = $post ? $post->ID : 0;

	/**
	 * Filters the returned comment count for a post.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $count   A string representing the number of comments a post has, otherwise 0.
	 * @param int        $post_id Post ID.
	 */
	return apply_filters( 'get_comments_number', $count, $post_id );
}

常見問題

FAQs
檢視更多 >