get_next_post_link()
云策文档标注
概述
get_next_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 参数设置为 false 以获取下一个文章。
- 相关函数包括 get_adjacent_post_link()、get_the_post_navigation() 和 next_post_link()。
- 自 WordPress 3.7.0 版本引入。
原文内容
Retrieves the next 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_next_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, false, $taxonomy );
}
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |