• Resolved mizzmuzikluvr

    (@mizzmuzikluvr)


    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.

    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)
  • 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.

    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

    (@mizzmuzikluvr)

    The theme was originally Infinity by smashing magazine.

    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!

    Did you understand how to apply Jurre’s answer to your situation?

    Thread Starter mizzmuzikluvr

    (@mizzmuzikluvr)

    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

    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.
    ?>

    Thread Starter mizzmuzikluvr

    (@mizzmuzikluvr)

    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

    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

    (@mizzmuzikluvr)

    Thanks vtxyzzy. Thats seems to have done it! Thanks so much!

    Kayla

    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.