^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_page_of_comment()用法示例

get_page_of_comment( int $comment_ID,  array $args = array() )

Calculate what page number a comment will appear on for comment paging.


描述


参数

$comment_ID

(int)
(Required)
Comment ID.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$args

(array)
(Optional)
Array of optional arguments.

  • ‘type’
    (string) Limit paginated comments to those matching a given type. Accepts ‘comment’, ‘trackback’, ‘pingback’, ‘pings’ (trackbacks and pingbacks), or ‘all’. Default is ‘all’.
  • ‘per_page’
    (int) Per-page count to use when calculating pagination. Defaults to the value of the ‘comments_per_page’ option.
  • ‘max_depth’
    (int|string) If greater than 1, comment page will be determined for the top-level parent of $comment_ID. Defaults to the value of the ‘thread_comments_depth’ option.

Default value: array()


返回值

(int|null) Comment page number or null on error.


源代码

File: wp-includes/comment.php

function get_page_of_comment( $comment_ID, $args = array() ) {
	global $wpdb;

	$page = null;

	if ( !$comment = get_comment( $comment_ID ) )
		return;

	$defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
	$args = wp_parse_args( $args, $defaults );
	$original_args = $args;

	// Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
	if ( get_option( 'page_comments' ) ) {
		if ( '' === $args['per_page'] ) {
			$args['per_page'] = get_query_var( 'comments_per_page' );
		}

		if ( '' === $args['per_page'] ) {
			$args['per_page'] = get_option( 'comments_per_page' );
		}
	}

	if ( empty($args['per_page']) ) {
		$args['per_page'] = 0;
		$args['page'] = 0;
	}

	if ( $args['per_page'] < 1 ) {
		$page = 1;
	}

	if ( null === $page ) {
		if ( '' === $args['max_depth'] ) {
			if ( get_option('thread_comments') )
				$args['max_depth'] = get_option('thread_comments_depth');
			else
				$args['max_depth'] = -1;
		}

		// Find this comment's top level parent if threading is enabled
		if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
			return get_page_of_comment( $comment->comment_parent, $args );

		$comment_args = array(
			'type'       => $args['type'],
			'post_id'    => $comment->comment_post_ID,
			'fields'     => 'ids',
			'count'      => true,
			'status'     => 'approve',
			'parent'     => 0,
			'date_query' => array(
				array(
					'column' => "$wpdb->comments.comment_date_gmt",
					'before' => $comment->comment_date_gmt,
				)
			),
		);

		$comment_query = new WP_Comment_Query();
		$older_comment_count = $comment_query->query( $comment_args );

		// No older comments? Then it's page

更新日志

Version 描述
2.7.0 Introduced.

相关函数

Uses

  • wp-includes/comment.php:
    get_page_of_comment
  • wp-includes/class-wp-comment-query.php:
    WP_Comment_Query::__construct()
  • wp-includes/query.php:
    get_query_var()
  • wp-includes/functions.php:
    wp_parse_args()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/option.php:
    get_option()
  • wp-includes/comment.php:
    get_page_of_comment()
  • wp-includes/comment.php:
    get_comment()
  • Show 3 more uses


Used By

  • wp-includes/comment-template.php:
    get_comment_link()
  • wp-includes/comment.php:
    get_page_of_comment()

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈