get_comments_number() - WordPress 函数参考中文文档

返回介绍

get_comments_number()

发布于 2017-09-10 字数1934 浏览 961 评论 0

get_comments_number( int|WP_Post $post_id )

Retrieve the amount of comments a post has.


描述


参数

$post_id

(int|WP_Post)
(Optional)
Post ID or WP_Post object. Default is global $post.


返回值

(int) The number of comments a post has.


源代码

File: wp-includes/comment-template.php

function get_comments_number( $post_id = 0 ) {
	$post = get_post( $post_id );

	if ( ! $post ) {
		$count = 0;
	} else {
		$count = $post->comment_count;
		$post_id = $post->ID;
	}

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

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/post.php:
    get_post()
  • wp-includes/comment-template.php:
    get_comments_number

Used By

  • wp-includes/embed.php:
    print_embed_comments_button()
  • wp-includes/comment-template.php:
    get_comments_number_text()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::comments_bubble()
  • wp-includes/comment-template.php:
    comments_popup_link()
  • wp-includes/comment-template.php:
    get_comments_link()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!