This question may look foolish to everyone or novice , but i am working on a theme . It will be basically a news publishing theme .

Right now , In my home page all posts are showing one after another like a usual WordPress theme.

No extra coding has been implemented on the theme .

But i want to make different sections on the home page and naming each section as its

category's title and pulling the posts from that category and show them in that section .

Like other news related themes do by making blocks in their home page and showing posts like " breaking news " , " hot right now " etc

I hope you have got the point that i am saying .

I have read about custom post types and wp_query posts but i dont have the code exactly i want for this .

Any kind of help will be very much appreciated


  • how are the categories selected? automatic from the site? from theme options?
    – Michael
    May 17, 2012 at 15:29
  • from theme option actually May 17, 2012 at 16:03

1 Answer 1


You can run a foreach loop through all your categories then run a query for the latest posts in each category. You can do this by setting your home page to a static page then put this in a custom template. This is just a basic example:

$categories = get_the_categories();
    foreach ( $categories as $cat ) {

    $exclude = isset( $GLOBALS['current_id'] ) ? $GLOBALS['current_id'] : null;
    $args = array(
         'cat' => $cat->term_id,
         'posts_per_page' => 4,
         'post__not_in' => array( $exclude ),
         'no_found_rows' => true,

     echo '<h3>'. $cat->name . '</h3>';
     $home_q = new WP_Query( $args );
     while ( $home_q->have_posts() ) : $home_q->the_post();
     $GLOBALS['current_id'] = get_the_ID();

     // Do loop stuff here......

     endwhile; wp_reset_postdata();


The $GLOBALS['current_id'] will hold an array of post ids to use in each additional query to prevent a post from showing up more than 1 time if it's in multiple categories. Setting 'no_found_rows` to true will make the query less taxing by not getting all the posts for pagination and stuff.

  • hey Chris_O , can i get the id from the option panel? i am using theming option framework . Oct 2, 2012 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.