Title: The Loop problems
Last modified: August 18, 2016

---

# The Loop problems

 *  Resolved [nbz](https://wordpress.org/support/users/nbz/)
 * (@nbz)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/the-loop-problems/)
 * Hi all.
 * I am trying to add a loop before the loop which shows the main page content. 
   The problem I am having is that apart from the homepage (which works), I am getting
   this error instead of the contents: “Sorry, no posts matched your criteria.”
 * The loop looks fine to me… am I missing something obvious? (on most pages I have
   four different loops with no errors. This fifth one seems to cause all the errors.
   I wrote/modified the others a year or two ago, so it may be something obvious
   I have since forgotten…)
 * The loop I added was:
 *     ```
       <div class="title">Affiliates</div>
       <div class="rtext">
       <?php
       $AffiliateCount = 0;
       $Affiliates = 3;
       ?>
       <?php query_posts('cat=60'); ?>
             <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
             <?php if ($AffiliateCount == $Affiliates ) {
       } else { ?>
       <div class="affiliate">
       	<?php the_content();
       			 $AffiliateCount = $AffiliateCount + 1; ?>
       </div>
       <?php	} ?>
       	<?php endwhile; else: ?>
       	<div class="noaffiliate">Affiliates will go here.</div>
       	<?php endif; ?>
       </div>
       ```
   
 * help?

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

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/the-loop-problems/#post-651363)
 * query_posts() should really be used only to affect the main (and hopefully only)
   loop on a page because it has a habit of banging the $posts object around in 
   ways people are not prepared for.
 * Try modifying your loop above like so and see if it works for you:
 *     ```
       <?php $aff_posts = new WP_Query('cat=60'); ?>
             <?php if ($aff_posts->have_posts()) : while ($aff_posts->have_posts()) : $aff_posts->the_post(); ?>
       ```
   
 *  Thread Starter [nbz](https://wordpress.org/support/users/nbz/)
 * (@nbz)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/the-loop-problems/#post-651413)
 * Thanks, that worked.
 * It was something I really did not know. Is this documented in the Codex?
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/the-loop-problems/#post-651414)
 * NBZ — there is this in Codex:
    [http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1](http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1)
 * If there are other places appropriate for that please suggest or even better,
   anyone can edit Codex.
 *  Thread Starter [nbz](https://wordpress.org/support/users/nbz/)
 * (@nbz)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/the-loop-problems/#post-651429)
 * Sorry, my mistake. I even looked at that page. Blame my stupidness.
 *  [Josh Fialkoff](https://wordpress.org/support/users/nooozeguy/)
 * (@nooozeguy)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/the-loop-problems/#post-651635)
 * Hi,
 * I am trying to use the loop to show excerpts from sub pages within a directory.
 * The page I am trying to do this on is: [http://mjoc.biz/news-articles-especially-for-brokers-agents/](http://mjoc.biz/news-articles-especially-for-brokers-agents/).
 * I would like to have the excerpt for each page under each bullet.
 * Here is the code in the template which draws the link.
 * I think I need to use the <?php the_excerpt(); ?> tag, but I am not sure how (
   or even if that is correct). 😉
 * Thanks for your help!
 * -Josh
 *     ```
       <?php the_content('<p class="serif">More &raquo;</p>'); ?>
       <ul>
         <?php
         wp_list_pages('title_li=&child_of='.$post->ID.'&date_format=$date_format'); ?>
       </ul>
   
       <!--
       	<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
       -->
       ```
   

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

The topic ‘The Loop problems’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 4 participants
 * Last reply from: [Josh Fialkoff](https://wordpress.org/support/users/nooozeguy/)
 * Last activity: [17 years, 8 months ago](https://wordpress.org/support/topic/the-loop-problems/#post-651635)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
