返回介绍

paginate_comments_links()

发布于 2017-09-11 09:53:07 字数 4426 浏览 1357 评论 0 收藏 0

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

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


description


参数

$args

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

Default value: array()


返回值

(string|void) Markup for pagination links.


源代码

File: wp-includes/link-template.php

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,
		'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'] )
		echo $page_links;
	else
		return $page_links;
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: trailingslashit()
  • wp-includes/general-template.php: paginate_links()
  • wp-includes/query.php: is_singular()
  • wp-includes/query.php: get_query_var()
  • wp-includes/functions.php: wp_parse_args()
  • wp-includes/functions.php: add_query_arg()
  • wp-includes/link-template.php: get_permalink()
  • wp-includes/link-template.php: user_trailingslashit()
  • wp-includes/class-wp-rewrite.php: WP_Rewrite::using_permalinks()
  • wp-includes/comment.php: get_comment_pages_count()
  • Show 5 more uses Hide more uses

Used By

  • wp-includes/link-template.php: get_the_comments_pagination()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Enhanced Comment Display

    WordPress makes comments.php files simple to write and edit. It’s simple to easily break comments into pages so that you don’t end up with hundreds of comments all loading on every pageview.

    You will need to set up the options in SETTINGS > DISCUSSION for paging to work.

    The easiest way to do so is with the following function, which prints out a link to the next and previous comment pages, as well as a numbered list of all the comment pages.

    
    paginate_comments_links( $args );
    

    It accepts an array or query-style list of arguments similar to get_posts() or get_terms().

    If you want more control, you can also use the simpler next and previous functions:

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

    and

    
    previous_comments_link( $label = "" );
    
  2. Custom Prev-/Next-links

    To modify the Prev- and Next-links, you can use the options ‘prev_text’ and ‘next_text’. These are provided by the function paginate_links().

    
    paginate_comments_links( array(
    	'prev_text  => 'back',
    	'next_text' => 'forward'
    ) );
    

    Note: If you want to use HTML entities in your ‘prev_text’ or ‘next_text’, you will have to use the array-based syntax.

    
    paginate_comments_links( array(
    	'prev_text' => '«',
    	'next_text' => '»'
    ) )
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文