这个has_tag() 必须在循环内使用conditional donot;它可以通过$post 对象作为第二个参数:
has_tag( $tag, $post );
自
has_tag() 默认为当前帖子,只需将对象传递给下一个相邻帖子即可。幸运的是,WordPress提供了检索相邻帖子的功能:
get_adjacent_post():
get_adjacent_post( $in_same_cat, $excluded_categories, $previous );
The
$in_same_cat 参数默认为
false, 这个
$excluded_categories 参数默认为
\'\', 还有
$previous 参数默认为
true. 所以,我们只需要将第三个参数改为
false, 要检索下一篇文章,而不是上一篇文章,请执行以下操作:
get_adjacent_post( false, \'\', true );
将其与
has_tag() 有条件的:
if ( has_tag( \'mario\', get_adjacent_post( false, \'\', true ) ) {
// Next post has the \'mario\' post tag;
// do something
}