• My site has a photo gallery. Each photo in the gallery is basically 1 post. Each posts gets lumped together to make the gallery.

    I wanted to display the most recent photo on the homepage. This is the code I used below:

    <?php query_posts('cat=71&showposts=1'); ?>
      <?php while (have_posts()) : the_post(); ?>
      <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
      <?php endwhile;?>

    It works fine except I just noticed that this code is changing the Title tags to that of the photo gallery page. When I remove this code It reverts to normal.

    Any idea why this is happening? Should I modify this code code or something, or should I modify wp_title?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jcprovideo

    (@jcprovideo)

    Any ideas?

    Thread Starter jcprovideo

    (@jcprovideo)

    Buller? I guess I can dig through one of the magazine themes out there and see how they accomplished it… I’ll post my findings

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Instead of using query_posts, consider creating a new, separate, query for your non-main-Loops.

    <?php $myQuery = new WP_Query('cat=71&showposts=1'); ?>
    <?php while ($myQuery->have_posts()) : $myQuery->the_post(); ?>
    <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    <?php endwhile;?>

    Using new queries like that prevents them from screwing up other things later on the page that rely on the main query.

    Alternatively, after you do muck with the main query, reset it by calling wp_reset_query();.

    Thread Starter jcprovideo

    (@jcprovideo)

    Wow, I didn’t know that. Thanks so much. Makes perfect since!

    Thread Starter jcprovideo

    (@jcprovideo)

    Hummm Not working…I wonder what I need to change

    Thread Starter jcprovideo

    (@jcprovideo)

    Well the <?php wp_reset_query();?> did the trick…I couldn’t get the other code you sent to work.

    <?php $myQuery = new WP_Query('cat=71&showposts=1'); ?>
    <?php while ($myQuery->have_posts()) : $myQuery->the_post(); ?>
    <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    <?php endwhile;?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    I don’t know why you could not get it to work, but that code is correct and it does work.

    Thread Starter jcprovideo

    (@jcprovideo)

    Thanks again!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘query_posts changes title tags’ is closed to new replies.