{$adjacent}_post_link
云策文档标注
概述
此文档介绍 {$adjacent}_post_link 过滤器,用于修改相邻文章链接的输出。过滤器名称中的动态部分 $adjacent 指定链接类型为“next”或“previous”。
关键要点
- 过滤器名称基于 $adjacent 参数动态生成,例如 next_post_link 和 previous_post_link。
- 参数包括 $output(链接字符串)、$format(锚点格式)、$link(永久链接格式)、$post(相邻文章对象或空字符串)和 $adjacent(链接类型)。
- 此过滤器在 get_adjacent_post_link() 函数中调用,用于控制相邻文章链接的最终输出。
代码示例
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );注意事项
- 从 WordPress 4.2.0 版本开始添加了 $adjacent 参数,2.6.0 版本引入此过滤器。
- 如果不存在对应的相邻文章,$post 参数可能为空字符串。
原文内容
Filters the adjacent post link.
Description
The dynamic portion of the hook name, $adjacent, refers to the type of adjacency, ‘next’ or ‘previous’.
Possible hook names include:
next_post_linkprevious_post_link
Parameters
$outputstring-
The adjacent post link.
$formatstring-
Link anchor format.
$linkstring-
Link permalink format.
$postWP_Post|string-
The adjacent post. Empty string if no corresponding post exists.
$adjacentstring-
Whether the post is previous or next.
Source
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );