函数文档

the_posts_navigation()

💡 云策文档标注

概述

the_posts_navigation() 是一个 WordPress 模板标签函数,用于在适用时显示文章分页导航(如“上一页/下一页”链接)。它基于 get_the_posts_navigation() 函数实现,通过参数数组自定义导航元素。

关键要点

  • 函数作用:输出文章分页导航,适用于多页文章列表场景。
  • 参数:接受一个可选的 $args 数组参数,用于自定义导航文本、ARIA 标签、类名等,具体参数参考 get_the_posts_navigation()。
  • 实现方式:内部调用 get_the_posts_navigation() 并直接输出结果,无返回值。
  • 相关函数:get_the_posts_navigation() 返回导航 HTML 字符串,而 the_posts_navigation() 直接输出。
  • 版本历史:自 WordPress 4.1.0 版本引入。

代码示例

the_posts_navigation( array(
    'prev_text' => '上一页文章',
    'next_text' => '下一页文章',
    'screen_reader_text' => '文章导航',
    'aria_label' => '文章',
    'class' => 'custom-posts-navigation'
) );

📄 原文内容

Displays the navigation to next/previous set of posts, when applicable.

Parameters

$argsarrayoptional
See get_the_posts_navigation() for available arguments.

More Arguments from get_the_posts_navigation( … $args )

Default posts navigation arguments.

  • prev_text string
    Anchor text to display in the previous posts link.
    Default ‘Older posts’.
  • next_text string
    Anchor text to display in the next posts link.
    Default ‘Newer posts’.
  • screen_reader_text string
    Screen reader text for the nav element.
    Default ‘Posts navigation’.
  • aria_label string
    ARIA label text for the nav element. Default 'Posts'.
  • class string
    Custom class for the nav element. Default 'posts-navigation'.

Default:array()

Source

function the_posts_navigation( $args = array() ) {
	echo get_the_posts_navigation( $args );
}

Changelog

Version Description
4.1.0 Introduced.