我正在处理此代码,以便通过任何标记帖子显示我的相关内容,但它会将我的缩略图显示为具有相同标记的帖子的链接两次。
我如何强制此仅显示一次相关帖子? 如果你有> = 2发布2个相同的标签,你会得到加倍的值
<?php
global $post;
$nextTagThumb='-1';
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag) :
?>
<?php
if ($tags) {
$what_tag = $tags[($nextTagThumb+'1')]->term_id;
$args=array(
'tag__in' => array($what_tag),
'post__not_in' => array($post->ID),
'showposts'=>100,
'ignore_sticky_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</li>
<?php
endwhile;
}
wp_reset_query();
$nextTagThumb = ($nextTagThumb+1);
}
?>
<?php endforeach; ?>