我在服装模板中为显示类别存档创建了category.php .
在类似页面链接中,如下所示:http://www.example.com/category/cat1/
通过这些代码,它可以显示 cat1 的最后一项
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Some template code
<?php endwhile; ?>
<?php endif; ?>
但是当我尝试通过 WP_Query 或 query_posts 而不是 cat1 的内容自定义查询时,它会显示所有类别网站的内容
<?php query_posts( 'posts_per_page=30' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Some template code
<?php endwhile; ?>
<?php endif; ?>
什么是理由和解决方案?
1 回答
您必须在查询中定义cat .
这是你的答案: