render_block_core_comments_pagination_numbers

函数
render_block_core_comments_pagination_numbers ( $attributes, $content, $block )
参数
  • (array) $attributes Block attributes.
    Required:
  • (string) $content Block default content.
    Required:
  • (WP_Block) $block Block instance.
    Required:
返回值
  • (string) Returns the pagination numbers for the comments.
定义位置
相关方法
register_block_core_comments_pagination_numbersrender_block_core_comments_pagination_nextrender_block_core_comments_paginationrender_block_core_comments_pagination_previousrender_block_core_query_pagination_numbers
引入
-
弃用
-

render_block_core_comments_pagination_numbers: 这个函数用来渲染WordPress中的评论分页数字块。评论分页数字块显示的是评论的页数: 这个函数负责生成评论分页数字块的HTML标记。

在服务器上渲染`core/comments-pagination-numbers’区块。

function render_block_core_comments_pagination_numbers( $attributes, $content, $block ) {
	// Bail out early if the post ID is not set for some reason.
	if ( empty( $block->context['postId'] ) ) {
		return '';
	}

	$comment_vars = build_comment_query_vars_from_block( $block );

	$total   = ( new WP_Comment_Query( $comment_vars ) )->max_num_pages;
	$current = ! empty( $comment_vars['paged'] ) ? $comment_vars['paged'] : null;

	// Render links.
	$content = paginate_comments_links(
		array(
			'total'     => $total,
			'current'   => $current,
			'prev_next' => false,
			'echo'      => false,
		)
	);

	if ( empty( $content ) ) {
		return '';
	}

	$wrapper_attributes = get_block_wrapper_attributes();

	return sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		$content
	);
}

常见问题

FAQs
查看更多 >