Title: Modify the loop on single post&#8230;
Last modified: August 19, 2016

---

# Modify the loop on single post…

 *  Resolved [mizzmuzikluvr](https://wordpress.org/support/users/mizzmuzikluvr/)
 * (@mizzmuzikluvr)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/)
 * Hey everyone, thanks for taking a look at this. Any help would be appreciated.
 * I have a thumbnail gallery that, on the main page, pulls an image from each post
   and displays it. The trouble is, that thumbnail calls from:
 * `<?php if (have_posts()) : while (have_posts()) : the_post(); ?>`
 * Which, I realize is “The Loop”.
 * The trouble is, when on my single posts, the gallery is only showing the information
   from THAT post. Instead of all of them.
 * You can see it at [the site.](http://kaylasrodawa.com)
 * I’m really not strong enough in my php knowledge to fix it. How do I make the
   loop pull from all of my posts, regardless of if we’re already on a single post?
 * Thanks!
 * Kayla

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600470)
 * If your theme is a free one, post a link to where it can be downloaded and the
   code examined.
 * Otherwise, you might get some help from the theme provider.
 *  [Jurre](https://wordpress.org/support/users/jurre/)
 * (@jurre)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600473)
 * You can create a new WP_Query object and use that in a secondary loop to query
   all posts and display the gallery.
 * Something like
 *     ```
       $my_query = new WP_Query;
       $my_query->query(array('cat' => 1));
   
       while($my_query->have_posts())
       {
           $my_query->the_post();
       //    the_title(); and all the usual stuff goes here
       }
       ```
   
 *  Thread Starter [mizzmuzikluvr](https://wordpress.org/support/users/mizzmuzikluvr/)
 * (@mizzmuzikluvr)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600483)
 * The theme was originally [Infinity by smashing magazine.](http://www.smashingmagazine.com/2008/08/08/infinity-a-free-wordpress-theme/)
 * But its been severely modified. The code in question is:
 *     ```
       <div id="ancillary">
       <div class="flickr">
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
         			<div class="post" id="post-<?php the_ID(); ?>">
   
       <!-- thumbnail wrapper -->
       <div class="thumb2 main">
   
       <!-- 235150image-covers -->
       <?php $image = get_post_meta($post->ID, 'thumbnail', true); ?>
       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php echo $image; ?>" alt="" /></a>
       <!-- 235150image end -->
   
         			</div>
         			</div>
         		  <?php endwhile; ?>
   
         		  <?php else : ?>
         		  <div class="post single">
           			<h2>No matching results</h2>
           			<div class="entry">
           				<p>You seem to have found a mis-linked page or search query with no associated or related results.</p>
           			</div>
           		</div>
         		<?php endif; ?>
   
       <!-- page navi -->
       <div class="pagenavi">
       <?php if(function_exists('wp_pagenavi')) { wp_pagenavi('', '', '', '', 3, false);} ?>
       </div>
       <!-- page navi end --></div>
   
       <div class="clear"></div>
   
       </div>
       </div>
       ```
   
 * Thanks for all your help!
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600490)
 * Did you understand how to apply Jurre’s answer to your situation?
 *  Thread Starter [mizzmuzikluvr](https://wordpress.org/support/users/mizzmuzikluvr/)
 * (@mizzmuzikluvr)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600577)
 * No actually, I’m not sure. I mean, I’m pretty good at C/P and other such n00b
   editing, but I’m not well versed.
 * Kayla
 *  [Jurre](https://wordpress.org/support/users/jurre/)
 * (@jurre)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600597)
 * From what I can understand from the given piece of code, I think the following
   would probably be a solution.
 * Try changing this line:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 * To this:
 *     ```
       <?php
       $my_query = new WP_Query();
       $my_query->query();
   
       if($my_query->have_posts()):
          while($my_query->have_posts()):
            $my_query->the_post();
       ?>
       ```
   
 * You may want to pass some parameters to the query() function to control which
   and how many posts are shown, information on the available parameters can be 
   found [here](http://codex.wordpress.org/Function_Reference/query_posts).
    ?>
 *  Thread Starter [mizzmuzikluvr](https://wordpress.org/support/users/mizzmuzikluvr/)
 * (@mizzmuzikluvr)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600659)
 * Jurre,
 * THANK YOU so much! It sort of worked.
 * Its showing all of the thumbs now, but its also displaying this warning:
 * `Warning: Missing argument 1 for WP_Query::query(), called in /home/content/mydomainhere/
   html/wp-includes/query.php on line 2693`
 * Any thoughts?
 * Kayla
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600665)
 * It is difficult to know what query arguments are needed without being able to
   test the code. I suggest starting with this:
 *     ```
       <?php
       $args = array (
          'caller_get_posts' => 1,
       );
       $my_query = new WP_Query();
       $my_query->query($args);
   
       if($my_query->have_posts()):
          while($my_query->have_posts()):
            $my_query->the_post();
       ?>
       ```
   
 * You can add other arguments to the array as needed.
 *  Thread Starter [mizzmuzikluvr](https://wordpress.org/support/users/mizzmuzikluvr/)
 * (@mizzmuzikluvr)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600688)
 * Thanks vtxyzzy. Thats seems to have done it! Thanks so much!
 * Kayla
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600690)
 * You are welcome!

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

The topic ‘Modify the loop on single post…’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 3 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/modify-the-loop-on-single-post/#post-1600690)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
