函数文档

get_next_posts_page_link()

💡 云策文档标注

概述

get_next_posts_page_link() 函数用于检索下一页文章的链接,适用于分页查询场景。该函数从 WordPress 2.1.3 版本向后移植到 2.0.10。

关键要点

  • 函数返回下一页文章的链接 URL,类型为字符串或 void。
  • 参数 $max_page 可选,指定最大页数,默认值为 0。
  • 函数内部使用全局变量 $paged 和 is_single() 检查当前是否为单篇文章页面。
  • 通过 get_pagenum_link() 生成链接,并确保下一页不超过最大页数。

代码示例

function get_next_posts_page_link( $max_page = 0 ) {
	global $paged;

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

		$next_page = (int) $paged + 1;

		if ( ! $max_page || $max_page >= $next_page ) {
			return get_pagenum_link( $next_page ); 
		}
	}
}

注意事项

  • 函数仅在非单篇文章页面(即列表或归档页面)时有效。
  • 如果 $max_page 为 0 或大于等于下一页数,则返回链接;否则不返回。
  • 相关函数包括 is_single() 和 get_pagenum_link(),常用于 next_posts() 函数中。

📄 原文内容

Retrieves the next posts page link.

Description

Backported from 2.1.3 to 2.0.10.

Parameters

$max_pageintoptional
Max pages. Default 0.

Return

string|void The link URL for next posts page.

Source

function get_next_posts_page_link( $max_page = 0 ) {
	global $paged;

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

		$next_page = (int) $paged + 1;

		if ( ! $max_page || $max_page >= $next_page ) {
			return get_pagenum_link( $next_page );
		}
	}
}

Changelog

Version Description
2.0.10 Introduced.