Joshi Joshi - 4 months ago 12
HTML Question

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

I am new in wordpress. I have make a template for post. But I don't know how to get the all posts with one category on one page in wordpress. Can anyone please help me to sort out this problem?

Answer

Try the below code. you can add category id and post per page as you want.

 <?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; ?>