Support » Fixing WordPress » Multiple query_posts on the same page using loop.php

  • 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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    (@esmi)

    Forum Moderator

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

    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 🙂

    esmi

    (@esmi)

    Forum Moderator

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

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple query_posts on the same page using loop.php’ is closed to new replies.