函数文档

next_post_rel_link()

💡 云策文档标注

概述

next_post_rel_link() 函数用于输出当前文章的下一个相邻文章的关联链接。它基于 get_adjacent_post_rel_link() 实现,主要用于在模板中显示导航链接。

关键要点

  • 函数输出下一个相邻文章的关联链接,常用于文章导航。
  • 参数包括可选的标题格式、是否在同一分类术语中、排除的术语ID和分类法。
  • 默认分类法为 'category',可通过 $taxonomy 参数自定义。
  • 函数内部调用 get_adjacent_post_rel_link() 并传递参数,$in_same_term 控制是否在同一术语中。

代码示例

function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
}

注意事项

  • 确保在循环内使用此函数,以正确获取当前文章上下文。
  • 参数 $excluded_terms 可以是数组或逗号分隔的字符串,用于排除特定术语。
  • 自 WordPress 2.8.0 版本引入,相关函数为 get_adjacent_post_rel_link()。

📄 原文内容

Displays the relational link for the next post adjacent to the current post.

Description

See also

Parameters

$titlestringoptional
Link title format. Default '%title'.
$in_same_termbooloptional
Whether link should be in the same taxonomy term.

Default:false

$excluded_termsint[]|stringoptional
Array or comma-separated list of excluded term IDs.
Default empty.
$taxonomystringoptional
Taxonomy, if $in_same_term is true. Default 'category'.

Source

function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
}

Changelog

Version Description
2.8.0 Introduced.