WordPress函数:get_next_comments_link 获取下个评论的链接

江河/ 2023年06月09日/ WordPress/ 浏览 765

函数原型:


get_next_comments_link( string $label = '', int $max_page ): string|void


获取下个评论链接。下一页评论的HTML格式链接。


参数说明:


$label,链接文本的标签。默认值:“”。


$max_page,最大页面。


函数源码:


function get_next_comments_link( $label = '', $max_page = 0 ) {
	global $wp_query;

	if ( ! is_singular() ) {
		return;
	}

	$page = get_query_var( 'cpage' );

	if ( ! $page ) {
		$page = 1;
	}

	$next_page = (int) $page + 1;

	if ( empty( $max_page ) ) {
		$max_page = $wp_query->max_num_comment_pages;
	}

	if ( empty( $max_page ) ) {
		$max_page = get_comment_pages_count();
	}

	if ( $next_page > $max_page ) {
		return;
	}

	if ( empty( $label ) ) {
		$label = __( 'Newer Comments »' );
	}

	$attr = apply_filters( 'next_comments_link_attributes', '' );

	return sprintf(
		'<a href="%1$s" %2$s>%3$s</a>',
		esc_url( get_comments_pagenum_link( $next_page, $max_page ) ),
		$attr,
		preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label )
	);
}


包含钩子:


apply_filters( 'next_comments_link_attributes', string $attributes )


发表评论

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

客服 工单