Php Wordpress类别其他条件不工作
我正在尝试设置一种按类别显示相关帖子并排除当前帖子的方法,但是当一个类别只有一篇帖子时,我当前显示其他任何内容的代码就不起作用了 这是我到目前为止掌握的代码。你知道为什么吗Php Wordpress类别其他条件不工作,php,wordpress,categories,Php,Wordpress,Categories,我正在尝试设置一种按类别显示相关帖子并排除当前帖子的方法,但是当一个类别只有一篇帖子时,我当前显示其他任何内容的代码就不起作用了 这是我到目前为止掌握的代码。你知道为什么吗 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1><?php the_title() ?></h1> <?php the_content();?> <?php $cur
<?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');?>
对不起!这一类别中没有更多的相关职位
不确定问题的原因,但不建议使用query\u posts
进行除更换主回路以外的任何操作(请参阅);显然它有各种各样的副作用。尝试get\u posts
或WP\u Query
。如果使用WP\u查询
参数post\u not\u in
@Hobo将其排除,您可能可以避免post id检查。谢谢您指出我。虽然我没有让这段代码工作,但我还是遵循了你关于查询帖子的建议。