WordPress.org

Ready to get started?Download WordPress

Forums

Multiple query_posts on the same page using loop.php (5 posts)

  1. teauser
    Member
    Posted 3 years ago #

    Hello and thank you for reading this.

    Does anyone know how to have two different query_posts on the same page if the twentyen theme (with loop.php) is being used?

    I would like to show the first post of different categories on different divs on the same page.

    Thanks a lot!

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Run a second loop/query after loop php has been called.

  3. teauser
    Member
    Posted 3 years ago #

    Hi esmi, thank you for your reply.

    The problem is that I'm using the loop.php file from the Twentyen theme and it's just one loop for all pages.

    Thanks for your help :)

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    You can still have a second loop - after get_template_part( 'loop', 'index' ); in index.php for example.

  5. Digital Raindrops
    Member
    Posted 3 years ago #

    In the index.php or better still a template page, you should limit the posts as well add &'posts_per_page' => 5

    //Do Layout stuff
    //Query One
    $args=array(
       'cat'=> 3,
       'posts_per_page' => 5,
    );
    query_posts($args);
    
    //Get the Posts
    get_template_part( 'loop', 'index' );
    wp_reset_query();
    
    //Do Layout Stuff
    //Query Two
    $args=array(
       'cat'=>4,
       'posts_per_page' => 5,
    );
    query_posts($args);
    
    //Get the Posts
    get_template_part( 'loop', 'index' );
    wp_reset_query();
    
    //Do Layout Stuff
    //Query Three
    $args=array(
       'cat'=>7,
       'posts_per_page' => 5,
    );
    query_posts($args);
    
    //Get the Posts
    get_template_part( 'loop', 'index' );
    wp_reset_query();
    
    wp_reset_postdata();
    //Get the Original Page ID for comments etc:

    HTH

    David

Topic Closed

This topic has been closed to new replies.

About this Topic