prev_post_rel_link()
云策文档标注
概述
prev_post_rel_link() 是一个 WordPress 函数,用于显示当前文章相邻的前一篇文章的关系链接。它基于 get_adjacent_post_rel_link() 实现,并支持通过参数控制链接标题、是否在同一分类术语中以及排除特定术语。
关键要点
- 函数用于输出前一篇文章的链接,常用于文章导航。
- 参数包括 $title(链接标题格式,默认 '%title')、$in_same_term(是否在同一分类术语中,默认 false)、$excluded_terms(排除的术语 ID 数组或逗号分隔列表,默认空字符串)和 $taxonomy(分类法,默认 'category')。
- 内部调用 get_adjacent_post_rel_link() 函数,传递参数并设置 $previous 为 true 以获取前一篇文章链接。
- 自 WordPress 2.8.0 版本引入,位于 wp-includes/link-template.php 文件中。
代码示例
function prev_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, true, $taxonomy );
}
原文内容
Displays the relational link for the previous 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 true. $taxonomystringoptional-
Taxonomy, if
$in_same_termis true. Default'category'.
Source
function prev_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, true, $taxonomy );
}
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |