當我爲最近的帖子寫下面的代碼,然後在我爲下一個和上一個鏈接編寫代碼之後,那個函數會給我同一個帖子的鏈接。如果我評論「$ tags = wp_get_post_tags($ post-> ID);」這行然後它會打印下一篇文章鏈接。我該如何解決這個錯誤?請幫幫我。next_post_link()函數在wordpress中給出相同的帖子URL
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo '<div class="articlecontent font16 bold fontgray">Related Posts</div>';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if($my_query->have_posts()) {
echo '<div class="articlecontent"><ul>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
echo "</ul></div>";
}
}
?>
<div class="nextprevbar">
<div class="prevtopic"><?php
previous_post_link('%link', '<img border="0" alt="" src="'.get_template_directory_uri().'/images/prev-bullet.gif">' . _x(' ', 'Previous post link', 'twentyten') . ' %title'); ?></div>
<div class="nexttopic"><?php next_post_link('%link', '%title <img border="0" alt="" src="'.get_template_directory_uri().'/images/next-bullet.gif">' . _x(' ', 'Next post link', 'twentyten') . '</span>'); ?></div>
</div>