adjacent_posts_rel_link()
云策文档标注
概述
adjacent_posts_rel_link() 函数用于显示当前文章相邻文章的关联链接,通常用于单篇文章页面以提供前后导航。它基于 get_adjacent_post_rel_link() 实现,支持自定义标题格式、同分类项和排除术语等参数。
关键要点
- 函数功能:输出相邻文章的关联链接,包括前一篇和后一篇。
- 参数说明:$title 控制链接标题格式,默认 '%title';$in_same_term 指定是否在同一分类项中;$excluded_terms 用于排除术语ID;$taxonomy 设置分类法,默认 'category'。
- 内部实现:调用 get_adjacent_post_rel_link() 两次,分别处理前一篇和后一篇链接。
- 相关函数:get_adjacent_post_rel_link() 用于检索链接,adjacent_posts_rel_link_wp_head() 用于在头部显示。
- 版本历史:自 WordPress 2.8.0 引入。
代码示例
function adjacent_posts_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 );
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
}
原文内容
Displays the relational links for the posts adjacent to the current post.
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_termis true. Default'category'.
Source
function adjacent_posts_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 );
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
}
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |