Html 将特定数量的帖子从类别添加到主页

Html 将特定数量的帖子从类别添加到主页,html,wordpress,Html,Wordpress,请我试图添加特定数量的职位(5个职位)从一个类别的主页,但它不工作 am当前使用的代码没有显示5篇文章,而是显示了该类别的25篇文章 <div id="content"> <ul class="disclosure table group"> <?php $catquery = new WP_Query( 'posts_per_page=5&cat=158' ); ?> <?php while($catquery->have_posts

请我试图添加特定数量的职位(5个职位)从一个类别的主页,但它不工作

am当前使用的代码没有显示5篇文章,而是显示了该类别的25篇文章

<div id="content"> 
<ul class="disclosure table group"> 
<?php $catquery = new WP_Query( 'posts_per_page=5&cat=158' ); ?>
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<li style="text-align: justify; font-weight: 500; color: #cc3366;">
<a href="<?php the_permalink(); ?>" style="color: #cc3366;" title="<?php the_title(); ?>">
<span style="font-size: 12px;"><?php the_title(); ?> </span>
</a> 
</li> 
<?php endwhile; 
wp_reset_postdata(); ?> 
</ul>
</div>


这样编写代码,wp\u查询的cat属性是一个数组。 所以代码应该像下面这样

$args = array(
        'post_type' => 'post',
        'cat' => array(158),
        'posts_per_page'=>5,
);
$catquery = new WP_Query($args); 
 while($catquery->have_posts()) : $catquery->the_post(); 

//your code goes here

 endwhile; 
 wp_reset_postdata();

请尝试代码,然后告诉我结果。谢谢>这是我目前使用的代码,但无法正常工作。请使用edit buton将代码直接发布到您的问题中。仍然显示相同的25篇文章,无法在5篇文章中工作扫描您告诉我,您在哪个文件中添加了代码?将代码添加到my-post-default.php以在主页上显示分类文章我想,上一个查询不会重置。因此,尝试添加wp_reset_query();在编写代码之前,请让我知道结果。如果这样做有效,那么前面的查询将阻碍此查询。