next_posts()
云策文档标注
概述
next_posts() 函数用于显示或检索下一页文章的链接,常用于分页导航。它基于 get_next_posts_page_link() 获取链接,并根据参数决定是输出还是返回链接。
关键要点
- 函数接受两个可选参数:$max_page(最大页数,默认 0)和 $display(是否直接输出链接,默认 true)。
- 当 $display 为 true 时,函数直接输出链接;为 false 时,返回链接字符串。
- 函数内部调用 get_next_posts_page_link() 获取链接,并使用 esc_url() 进行 URL 清理。
- 相关函数包括 get_next_posts_link(),用于检索链接。
- 自 WordPress 0.71 版本引入,无后续变更记录。
原文内容
Displays or retrieves the next posts page link.
Parameters
$max_pageintoptional-
Max pages. Default 0.
$displaybooloptional-
Whether to echo the link.
Default:
true
Source
function next_posts( $max_page = 0, $display = true ) {
$link = get_next_posts_page_link( $max_page );
$output = $link ? esc_url( $link ) : '';
if ( $display ) {
echo $output;
} else {
return $output;
}
}
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |