日期:2014-05-17 浏览次数:20639 次
<?php
//推荐文章
?>
<div id="recommend">
<?php
$cat_id="";
foreach((get_the_category()) as $category) {
//get category id
$cat_id.= $category->cat_ID . ','; //当前文章的分类的ID
//echo $category->cat_name . ' '; //当前文章的分类的名称
}
$my_query = new WP_Query("cat=".$cat_id."&posts_per_page=5");
while ($my_query->have_posts()) : $my_query->the_post();?>
<li>
<span>
<? if ( has_post_thumbnail() ) { ?>
<img src="<?php get_image_url(); ?>" alt="" title="<?php echo short_title('...', 5); ?>" /></span>
<? }else{?>
<img src="<?php bloginfo('template_directory'); ?>/images/dummy.png" alt="" title="<?php echo short_title('...', 5); ?>" /></span>
<? }?>
<p><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
</li>
<?php
endwhile;
?>
<div class="clear"></div>
</div>
$cat_id.= $category->cat_ID . ','; //当前文章的分类的ID
------解决方案--------------------
"变成了给分类评论"?? 还是变成了给你最后一篇推荐文章评论? 评论后跳到了该文章?
检查你的$id是否被你加的这个loop改变了