[resolved] How can I display two posts per category on the home page? (5 posts)

  1. Greeny106
    Posted 6 years ago #

    Hello, I have been bashing my head against a wall now for around three hours. All I want to do is display two posts for each category, by the following category order (Featured Plus > Featured > Standard) or by ID (4, 3, 1).

    I tried several plugins but none of them worked as needed, I tried using query_posts functions to display the posts, but you can't seem to order by category how I would like...

    So, my last resort is seeking help here.

    Thanks in advance, any help would be appreciated,
    Tom Green.

  2. MichaelH
    Posted 6 years ago #

    foreach( array(4, 3, 1) as $cat_id ) {
        'cat' => $cat_id,
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => 2,
        'caller_get_posts'=> 1
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of Posts for category '. $cat_id;
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        //the_content();  //or the_excerpt{};
    wp_reset_query();  // Restore global post data stomped by the_post().
  3. Greeny106
    Posted 6 years ago #

    Brilliant! Thank you so much, works like a charm, just styled it into the previous code and it looks exactly as it should!

    Thank you again, greatly appreciated!

  4. PowerPro
    Posted 5 years ago #

    Hello...I'm interested in the same thing but not in any category order. Right now, it's showing all the latest posts from all categories in chronological order with the most recent first...

    And I'd like to instead have the latest two from each category show up on the homepage still in chronological order for all categories.

    Help please?

  5. Michael
    Forum Moderator
    Posted 5 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic