paginate_comments_links()

最后更新于:2021-11-27 18:25:25

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

Displays or retrieves pagination links for the comments on the current post.

参数

$args

(string|array) (Optional) args. See paginate_links().

Default value: array()

响应

(void|string|array) Void if ‘echo’ argument is true and ‘type’ is not an array, or if the query is not for an existing single post of any post type. Otherwise, markup for comment page links or array of comment page links, depending on ‘type’ argument.

源文件

文件: gc-includes/link-template.php

function paginate_comments_links( $args = array() ) {
	global $gc_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 ( $gc_rewrite->using_permalinks() ) {
		$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $gc_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
	}

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

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