get_previous_post_link()
云策文档标注
概述
get_previous_post_link() 函数用于检索与当前文章相邻的前一篇文章的链接。它基于 get_adjacent_post_link() 实现,支持自定义链接格式和分类限制。
关键要点
- 函数返回字符串类型的链接 URL,指向当前文章的前一篇文章。
- 参数包括 $format(链接锚点格式,默认 '« %link')、$link(链接永久链接格式,默认 '%title')、$in_same_term(是否在同一分类术语中,默认 false)、$excluded_terms(排除的术语 ID 数组或逗号分隔列表,默认空)、$taxonomy(分类法,当 $in_same_term 为 true 时使用,默认 'category')。
- 内部调用 get_adjacent_post_link() 函数,通过设置 $previous 参数为 true 来获取前一篇文章链接。
- 相关函数包括 get_adjacent_post_link()、get_the_post_navigation() 和 previous_post_link()。
- 自 WordPress 3.7.0 版本引入。
原文内容
Retrieves the previous post link that is adjacent to the current post.
Parameters
$formatstringoptional-
Link anchor format. Default ‘« %link’.
$linkstringoptional-
Link permalink 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 get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
}
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |