Wordpress类别别 - 条件不起作用

时间:2013-10-05 16:20:42

标签: php wordpress categories

我正在尝试设置一种按类别显示相关帖子并排除当前帖子的方法,但是当某个类别只有一个帖子时,我当前的代码显示其他任何内容都无效。

这是我到目前为止的代码。有什么想法吗?

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title() ?></h1> 

<?php the_content();?>

<?php $current_post_id = get_the_ID(); $post_cats = wp_get_post_categories( get_the_ID(), NULL );  ?> 
<?php query_posts('showposts=8&orderby=desc&cat='.implode(',',$post_cats)); if (have_posts()) : ?>

<?php $i=0; while (have_posts()) : the_post(); if($current_post_id==get_the_ID()) continue; $i++; ?>

<span class="related-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php short_title('...', 43); ?></a></span>

<?php endwhile;?>

<?php else : ?>
<p>Sorry! There is no more related posts in this category.</p>
<?php endif; wp_reset_query(); ?>           
<?php endwhile;endif ?>
<div style="clear:both;"></div>
<?php get_template_part('includes/loop-tips');?>

0 个答案:

没有答案