WordPress.org

Forums

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

  1. Greeny106
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    <?php
    foreach( array(4, 3, 1) as $cat_id ) {
      $args=array(
        '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>
          <?php
        //the_content();  //or the_excerpt{};
        endwhile;
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. Greeny106
    Member
    Posted 4 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!
    Tom.

  4. PowerPro
    Member
    Posted 4 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. alchymyth
    Forum Moderator
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic