我正在尝试在我的网站上显示特定类别的帖子,该帖子目前显示所有帖子。以下是我在下面部分的代码:
<?php
// the query
$wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>18)); ?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
答案 0 :(得分:0)
将循环中的代码更改为类似下面的代码,此处cat = 3
确定类别3.
<ul>
<?php
$catquery = new WP_Query( 'cat=3&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<li>
<h3>
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h3>
<?php the_content(); ?>
</li>
<?php endwhile; ?>
</ul>
答案 1 :(得分:0)
传递要显示帖子的参数cat = 3
或类别ID