繁体   English   中英

如何在Wordpress的一页上获取具有一个类别的所有帖子?

[英]How to get all posts with one category on one page in wordpress?

我是wordpress的新手。 我已经制作了一个发帖模板。 但是我不知道如何在wordpress中将所有带有一个类别的帖子发布到一页上。 谁能帮我解决这个问题?

试试下面的代码。 您可以添加类别ID并根据需要在每页上发帖。

 <?php
$catquery = new WP_Query( 'cat=3&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

另一种方法:

// The Query
query_posts( array(
      'category_name'  => 'my-category-slug',
      'posts_per_page' => -1
) ); 

// The Loop
while ( have_posts() ) : the_post();
    echo '<li>';
        the_title();
    echo '</li>';
endwhile;

// Reset Query
wp_reset_query();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM