WordPress.org

Forums

query_posts (5 posts)

  1. tom5436
    Member
    Posted 7 years ago #

    on query_posts is there a way to stop them if you have two loops on one page. My featured story loop is messing with my recent post loop

  2. tsguitar
    Member
    Posted 7 years ago #

    Give some more detail to explain the problem you're running into. If I understand your question, the answer is no -- query_posts doesn't offer a way to only run one of the loops on a page. But I think you can set up some if...else statements on the page to only run one of them at a time if you need to. Still, more information about exactly what you're trying to achieve would help answer your question.

  3. tom5436
    Member
    Posted 7 years ago #

    I have a featured story which I have a query post on it to show the highest rated post. And I also have recent posts at the bottom of the home page which I use a query post to order by date. My featured story's query is messing with my recent post and ordering it by highest rated

  4. tsguitar
    Member
    Posted 7 years ago #

    Do you end one query_posts loop before you begin the other one? I can't see them interfering with each other otherwise. Including a link to the way the page renders with both loops in action will help (think about putting your code in a pastebin somewhere because that might help, too).

  5. tom5436
    Member
    Posted 7 years ago #

    ya I end the loops before starting the next one. Here are the loops

    <?php query_posts('r_sortby=highest_rated');?>
    <?php $recent = new WP_Query("showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    <img src="<?php echo get_post_meta($post->ID, "thumbnail", true);?>" width="70">
    					<?php the_excerpt();?>
    <a href="<?php the_permalink()?>">Read More</a><div style="clear:both;"></div>
    					<?php endwhile; ?>
    <?php query_posts('r_sortby=highest_rated');?>
                                  <?php $recent = new WP_Query("cat=13&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    					<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b>
    <object width="300" height="246"><param name="movie" value="http://www.youtube.com/v/xLf_kvfguzE&hl=en&fs=1&rel=0&border=1"></param><param name="allowFullScreen" value="true"></param><embed src="<?php echo get_post_meta($post->ID, "Url", true);?>" type="application/x-shockwave-flash" allowfullscreen="true" width="300" height="246"></embed></object>
    <?php the_excerpt();?>
    <a href="<?php the_permalink()?>">Read More</a><div style="clear:both;"></div>
    					<?php endwhile; ?>
    query_posts('r_sortby=highest_rated');?>
                                  <?php $recent = new WP_Query("cat=34&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    					<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo get_post_meta($post->ID, "Hero_Name", true);?></a></b>
    <img src="<?php echo get_post_meta($post->ID, "thumbnail", true);?>" width="70">
    					<?php the_excerpt();?>
    <a href="<?php the_permalink()?>">Read More</a><div style="clear:both;"></div>
    					<?php endwhile; ?>
    <h2>Recent Posts</h2>
    <?php query_posts('orderby=date');?>
                           <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="recentpost"><hr width="600">
                            <img src="thumbnails/<?php echo get_post_meta($post->ID, "Thumbnail", true);?>">
                            <div class="leftrecent">
                            <h3><?php the_title();?></h3>
                            <?php the_excerpt();?><a href="<?php the_permalink()?>">Read More...</a>
                                  </div>
                            <div class="rightrecent">
                                  <span>Published: </span><?php the_time('F jS, Y') ?>
                                  <span>Author: </span><?php the_author() ?>
                                  <?php if(function_exists('the_ratings')) { the_ratings(); } ?>
                                  <?php if(function_exists('the_views')) { the_views(); } ?>
                                  <span>Category: </span><?php the_category(', ');?>
                                  </div>
                            </div>
                            <?php endwhile; ?>
                            <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic