函数文档

the_comments_navigation()

💡 云策文档标注

概述

the_comments_navigation() 是一个 WordPress 模板函数,用于在评论分页时显示导航链接,包括“上一页”和“下一页”评论。它基于 get_the_comments_navigation() 函数实现,并接受可选参数来自定义导航元素。

关键要点

  • 函数用于输出评论分页导航,适用于评论列表超过一页的情况。
  • 接受一个可选的 $args 数组参数,用于自定义导航文本、ARIA 标签、CSS 类等。
  • 内部调用 get_the_comments_navigation() 函数来生成导航 HTML,然后直接输出。
  • 自 WordPress 4.4.0 版本引入,是评论分页功能的核心模板标签之一。

代码示例

the_comments_navigation( array(
    'prev_text' => '更早的评论',
    'next_text' => '更新的评论',
    'aria_label' => '评论导航'
) );

注意事项

  • 参数 $args 是可选的,如果不提供,将使用默认值,如 'Older comments' 和 'Newer comments' 作为链接文本。
  • 确保在评论分页上下文中使用此函数,例如在 comments.php 模板文件中,否则可能不会显示任何内容。
  • 相关函数 get_the_comments_navigation() 可用于检索导航 HTML 而不直接输出,适合需要进一步处理的情况。

📄 原文内容

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

Parameters

$argsarrayoptional
See get_the_comments_navigation() for available arguments.

More Arguments from get_the_comments_navigation( … $args )

Default comments navigation arguments.

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

Default:array()

Source

function the_comments_navigation( $args = array() ) {
	echo get_the_comments_navigation( $args );
}

Changelog

Version Description
4.4.0 Introduced.