WordPress函数:paginate_comments_links 文章评论的分页

江河/ 2023年06月08日/ WordPress/ 浏览 883

函数原型:


paginate_comments_links( string|array $args = array() ): void|string|array


显示或检索当前文章评论的分页链接。


如果“echo”参数为true且“type”不是数组,或者查询不是针对任何帖子类型的现有单个帖子,则为空。


否则,评论页链接的标记或注释页链接数组,具体取决于“type”参数。


参数说明:


详细的参数说明可以参考:https://developer.wordpress.org/reference/functions/paginate_links/


函数源码:


function paginate_comments_links( $args = array() ) {
	global $wp_rewrite;

	if ( ! is_singular() ) {
		return;
	}

	$page = get_query_var( 'cpage' );
	if ( ! $page ) {
		$page = 1;
	}
	$max_page = get_comment_pages_count();
	$defaults = array(
		'base'         => add_query_arg( 'cpage', '%#%' ),
		'format'       => '',
		'total'        => $max_page,
		'current'      => $page,
		'echo'         => true,
		'type'         => 'plain',
		'add_fragment' => '#comments',
	);
	if ( $wp_rewrite->using_permalinks() ) {
		$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
	}

	$args       = wp_parse_args( $args, $defaults );
	$page_links = paginate_links( $args );

	if ( $args['echo'] && 'array' !== $args['type'] ) {
		echo $page_links;
	} else {
		return $page_links;
	}
}


使用举例:


next_comments_link( $label = "", $max_page = 0 );


发表评论

暂无评论,抢个沙发...

客服 工单