WordPress函数:get_next_posts_link 分页 下一页

江河/ 2023年07月05日/ WordPress/ 浏览 605

函数原型:


get_next_posts_link( string $label = null, int $max_page ): string|void


文章列表下一页的链接。返回 HTML 格式的下一篇文章页面链接。


参数说明:


$label 链接文字。


$max_page 最大页数。


函数源码:


function get_next_posts_link( $label = null, $max_page = 0 ) {
	global $paged, $wp_query;

	if ( ! $max_page ) {
		$max_page = $wp_query->max_num_pages;
	}

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

	$next_page = (int) $paged + 1;

	if ( null === $label ) {
		$label = __( 'Next Page »' );
	}

	if ( ! is_single() && ( $next_page <= $max_page ) ) {
		$attr = apply_filters( 'next_posts_link_attributes', '' );

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


包含钩子:


apply_filters( 'next_posts_link_attributes', string $attributes )


使用举例:


echo get_next_posts_link( __( 'Go to next page', 'textdomain' ) );


发表评论

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

客服 工单