Query Post by Category

This will query the post by its Category
 <?php
   // The Query
                                query_posts('posts_per_page=4' . '&category_name='.the_slug());
                                if (have_posts()) :
 // The Loop
                                while ( have_posts() ) : the_post();
                                    echo '<li><a href="';
                                    the_permalink();
                                    echo '">';
                                   the_title();
                                    echo '<br /></a></li>';
                                endwhile;
                     
  // If Nothing to show
                                else :
                                  echo '<li>No Recent Post</li>';
                               endif;
 // Reset Query
                             wp_reset_query();
  ?>
NOTE : I used custom slug function here.

Complete Reference Link Here

No comments: