函数文档

adjacent_post_link()

💡 云策文档标注

概述

adjacent_post_link() 是一个 WordPress 函数,用于显示相邻文章的链接,可以是上一篇或下一篇。它基于指定参数生成链接输出。

关键要点

  • 函数用于显示相邻文章链接,支持自定义格式和条件筛选。
  • 参数包括 $format(链接锚点格式)、$link(链接永久链接格式)、$in_same_term(是否在同一分类术语中)、$excluded_terms(排除的分类 ID)、$previous(是否显示上一篇链接)和 $taxonomy(分类法)。
  • 函数内部调用 get_adjacent_post_link() 来获取链接,然后直接输出。

代码示例

function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
	echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
}

📄 原文内容

Displays the adjacent post link.

Description

Can be either next post link or previous.

Parameters

$formatstringrequired
Link anchor format.
$linkstringrequired
Link permalink format.
$in_same_termbooloptional
Whether link should be in the same taxonomy term.

Default:false

$excluded_termsint[]|stringoptional
Array or comma-separated list of excluded category IDs.
Default empty.
$previousbooloptional
Whether to display link to previous or next post.

Default:true

$taxonomystringoptional
Taxonomy, if $in_same_term is true. Default 'category'.

Source

function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
	echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
}

Changelog

Version Description
2.5.0 Introduced.