Forums

The Loop twice on one page (3 posts)

  1. tbobker
    Member
    Posted 3 years ago #

    I have been using only one index page and this is to deal with both the homepage and other pages.

    The Loop is being used when on a category page or atual post.

    My problem is that i have designed my template so that i have latest post from a certain category and have used the loop a second time on the same page and well wordpress doent like it. It keeps showing results from the first loop rather than the second.

    How can i include "the Loop" twice on a single page so they work independantely so i can format the results?

    When i am mentioning the loop i mean this: http://codex.wordpress.org/The_Loop

  2. jbjweb
    Member
    Posted 3 years ago #

  3. t31os
    Member
    Posted 3 years ago #

    Do you second loop/query like this...

    <ul>
    <?php
        $myquery = new WP_Query();
        $myquery->query('showposts=5');
    ?>
    <?php while ($myquery->have_posts()) : $myquery->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    Adjust as required..

    If you needed a third do the same again just changing the new query variable name...

    <ul>
    <?php
        $anotherquery = new WP_Query();
        $anotherquery->query('showposts=5');
    ?>
    <?php while ($anotherquery->have_posts()) : $anotherquery->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    and so on..

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags