Support » Themes and Templates » Page title changes when using multiple loops?

  • I’m using two loops on the same page. No big deal.

    But now my tag, “<?php the_title(); ?>” doesn’t show the page of the title. Instead, it shows the title of the last post being displayed.

    For fun, I tried moving the tag to before the first loop, and the title went back to normal. It seems like some variable somewhere is not getting cleared or reset…

    Ideas?

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

    (@esmi)

    Forum Moderator

    What are you using for you 2 Loops – get_posts or query_posts?

    query_posts. Here are the two loops:

    This one gets Post Thumbnails (I’m using 2.9 beta)

    <?php query_posts('showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li>
    <?php the_post_image('full'); ?>
    </li>
    <?php endwhile;?>

    This one for excerpts

    <?php query_posts('showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><h2><?php the_title(); ?> | <?php the_time('m.j.y') ?></h2><?php the_excerpt(); ?></a></li>
    <?php endwhile;?>

    So with this code, I’m able to have post thumbnails in one div, excerpts in another.

    Bump for an answer!

    The problem even happens when using one loop on a page, but where the the_title tags comes well after the end of the loop, and this time, I’m using a secondary loop.

    <?php
    	$childProjects = new WP_Query();
    	$childProjects->query('post_type=pagepost_parent='.$post->ID);
    ?>
    <?php
    	while ($childProjects->have_posts()) : $childProjects->the_post();
    ?>
    <li>
    <?php
    	get_the_image( array('default_size' => 'full', 'link_to_post' => false) ); ?>
    </li>
    <?php endwhile;?>
    
    <h1><?php the_title(); ?></h1>

    lol

    THANKS EVERYONE!

    I found the answer. I had to reset the queue, to make sure it was dead.

    <?php wp_reset_query(); ?>

    This goes for other things too, like if you’re calling a post_thumbnail for the page after a have a loop that is collecting posts. The post_thumbnail for the last image will be called instead, unless you reset the query.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Page title changes when using multiple loops?’ is closed to new replies.