• Resolved wphax

    (@wphax)


    I’m having a problem displaying 3 loops on the homepage. I need them all to post from specific categories, loop 1 and 3 will be from the same category but not duplicating posts. Loop 2 will be taken from a different category. Here’s what I’m using now but it’s not working properly:

    Loop 1:

    <?php $my_query = new WP_Query('category_name=portfolio&posts_per_page=2');
                          while ($my_query->have_posts()) : $my_query->the_post();
                          $do_not_duplicate[] = $post->ID; ?>
                        	<li class="slide-thumb"><img class="slider-thumb" src="<?php echo get_post_meta($post->ID, 'Thumbnail', true) ?>" width="465" height="192" alt="" /></li>
                		<?php endwhile; ?>

    Loop 2:

    <?php $tempo_query = new WP_Query('category_name=blog&posts_per_page=1');
    			  while ($tempo_query->have_posts()) : $tempo_query->the_post();
    			  if (in_array($post->ID, $do_not_duplicate)) continue; update_post_caches($posts); ?>
    
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <p class="tahoma-font eleven-size excerpt-text"><?php the_excerpt(); ?></p>
                <p class="alignright tahoma-font eleven-size moretext"><a href="<?php the_permalink(); ?>">read more</a></p>
                <div class="clear"></div>
    
                <?php endwhile; ?>

    Loop 3:

    <?php $temp_query = new WP_Query('category_name=portfolio&posts_per_page=2');
    			  while ($temp_query->have_posts()) : $temp_query->the_post();
    			  if (in_array($post->ID, $do_not_duplicate)) continue; ?>
    
                	<div class="recent-item">
                        <img class="alignleft" src="<?php bloginfo('template_url'); ?>/images/mostrecent-thumb.png" width="61" height="61" alt="" />
                        <p class="recent-text alignright tahoma-font eleven-size"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> was created for <span>Caleb Spilchen</span>. <?php the_excerpt(); ?></p>
                        <div class="clear"></div>
                    </div>
    
                <?php endwhile; ?>

    I know I’m probably doing some unnecessary things in my code but I’m not really a PHP coder, nor do I understand it very well, but I can usually get it to work just not this time. If someone could help me out that would be awesome, thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter wphax

    (@wphax)

    Can anyone help…..?

    Not working in what capacity? Can you provide a little more information on the specifics of the problem with the third loop please.

    Suggestion: Try a reset after each query.. <?php wp_reset_query(); ?>

    Thread Starter wphax

    (@wphax)

    Well the last query isn’t displaying any posts. I have it set for the first query to display 2 posts from the category portfolio, and also the third query does the same thing, but I don’t want it to duplicate posts. Query 2 takes 1 post from the category blog. There’s 3 posts in the portfolio category, and the first loop is displaying the first 2, but the last loop is not displaying any posts at all.

    Thread Starter wphax

    (@wphax)

    The <?php wp_reset_query(); ?> code didn’t work, I put it just before each query but nothing changed.

    Thread Starter wphax

    (@wphax)

    Fixed my problem! I needed to offset the last query 2 posts, like this:

    $my_query = new WP_Query('category_name=portfolio&posts_per_page=2&offset=2');

    Just posting in case anyone else runs into this problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Last loop not displaying on a homepage with 3 loops’ is closed to new replies.