WordPress.org

Ready to get started?Download WordPress

Forums

Does in_category('') screws the_Loop ??? (3 posts)

  1. Blutarsky
    Member
    Posted 5 years ago #

    My index.php has 2 main loops, the first loop reads out say some 8 posts and then breaks the loop; then the second loop continues from where the first loop stopped:

    <?php /***************** FIRST Loop ******************/?>
    <?php if (have_posts()):?>
    	<?php while (have_posts())  : the_post(); update_post_caches($posts);?>
    ......Do Stuff
    ......and BREAK the loop say after 8 posts
    	<?php endwhile; ?>
    	<?php   else : ?>
    	  <div class="errorbox">
    		<?php
    		  _e('Sorry, no posts matched your criteria.', 'inove');?>
    	  </div>
    <?php  endif;?>
    
    <?php /***************** SECOND Loop ******************/?>
    <?php if (have_posts()):?>
    	<?php while (have_posts()): the_post();update_post_caches($posts);?>
    ......Do Stuff
    	<?php endwhile; ?>
    <?php  endif;?>

    and this works perfectly.

    But if just adding the following code at the beginning of the loop (inside the loop):
    <?php if (in_category('3')) continue; ?>

    screws up everything, in a way it looks like the loop is rewinded.
    Any hint?

  2. thelastknight
    Member
    Posted 5 years ago #

    If you are trying to just display that category in the loop. Try use this.

    <?php
    
    			$temp = $wp_query;
    
    			$wp_query= null;
    
    			$wp_query = new WP_Query();
    
    			$wp_query->query('cat=3&showposts=10'.'&paged='.$paged);
    
    			?>
    
    			<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  3. Blutarsky
    Member
    Posted 5 years ago #

    Ok, but I need to break the loop after a few posts and start again with another layout.... how do I keep the pointer to the last read record?

Topic Closed

This topic has been closed to new replies.

About this Topic