Bootstrap Templates Bundle

Tuesday, January 1, 2013

How to Display Recent Posts From A Specific Category In WordPress

For advance users who want to display recent posts from a specific category, we have this article specially for you. Beginner users will most likely not use this. This tutorial is mostly used in creating magazine style themes.


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

If you don't want to show post content then remove this below code

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

If you want to show post excerpt instead of post content
then change the upper code by
 
<?php the_excerpt(); ?>

No comments:

Post a Comment

Best Pest Control WordPress Themes 2017

A collection of best pest control WordPress Themes for pest control service providers.  Link:   https://devitems.com/review/best-pest-co...