views:

15

answers:

1

Alright I have two loops going, on in the body and on in the sidebar. I also have a conditional statement in the footer that generates another loop. The problem I'm running into is the use of the conditional statement in the footer. Because the loop in the sidebar was called last, Wordpress is using its variables in the conditional statement in the footer, and causing it to return false.

maybe there's some way to make some of the variables in loop in the body $_GLOBAL, that way I can use it later on and not have it conflict with the loop in the sidebar?

thanks

+1  A: 

Run a new query; you can run as many as you want within the standard WP loop. I don't what you're doing in your current loops, but this is an example of a new query that can coexist with the main WP loop as well as other instances of the query:

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>

Also see Function Reference/WP Query « WordPress Codex and Function Reference/wp reset query « WordPress Codex

songdogtech
worked perfectly. thanks. I suppose this method is better than using "query_posts?"
philmadelphia
I usually leave the main WP loop alone, unless it's on a very specific template page. The query above will run in posts and pages 9with php exec enabled) and in php-enabled widgets. See also the wp_reset_query doc link I added above.
songdogtech