• Resolved miowebdesigns

    (@miowebdesigns)


    I am using the loop twice on my index page. Once like this:

    [Code moderated per forum rules – please follow http://codex.ww.wp.xz.cn/Forum_Welcome#Posting_Code for posting code]

    The problem is that I get the results I am looking for on the first loop but the second one is blank. No results. I tried the same thing using query_posts(“posts_per_page=2”); with a wp_reset_query(); between but the results were the same. When I left out the post_per_page on the second loop the first loop is fine but the second loop shows all posts with no end. Anything?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter miowebdesigns

    (@miowebdesigns)

    You can’t see it because the code didn’t appear but that is exactly what I am doing.

    you can paste your full code in a paste bin if you want

    Thread Starter miowebdesigns

    (@miowebdesigns)

    Maybe this will show up.

    <!-- Start the Loop. -->
    			<?php
    			    $myquery = new WP_Query();
    			    $myquery->query('showposts=2');
    			?>
    			<?php
    			while ($myquery->have_posts()) : $myquery->the_post();
    			?>
    
    			<?php if ( in_category('projects') ) { ?>
    					 <li>
    					   <div id="homepage_projects_text" class="group">
    						<div class="home_projects_image">
    					<?php if(has_post_thumbnail()) {  ?>
    					<?php the_post_thumbnail('thumbnail');?>
    						<?php } else { ?>
    					<img src="<?php bloginfo('template_url'); ?>/images/no_image.png" alt="no image available"/>
    					<?php } ?>
    					    </div>
    					      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    				          <p><?php the_excerpt(); ?></p>
    					 </div>
    				    </li>
    						 <?php } ?>
    
    			<?php endwhile; ?>
    <!-- Start the Loop. -->
    	<?php
    	    $anotherquery = new WP_Query();
    	    $anotherquery->query('showposts=2');
    	?>
    	<?php
          while ($anotherquery->have_posts()) : $anotherquery->the_post();
    	?>
    	    <?php if ( in_category('blog') ) { ?>
    		       <li>
    				 <div id="blog_title">
    		         <div class="blog_date"><?php the_date(); ?></div>
    		           <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></div>
    		           <p><?php the_excerpt(); ?></p>
    		       </li>
    		<?php } ?>
    
    	<?php endwhile; ?>

    Hi

    The main problem you are having is it is selecting two posts in the second query, and since they are not in the blog category its not displaying them. You need to move the category selector into the query parameters

    second loop:

    <?php
    	    $anotherquery = new WP_Query();
    	    $anotherquery->query('showposts=2&category_name=blog');
    	?>
    	<?php
          while ($anotherquery->have_posts()) : $anotherquery->the_post();
    	?>
    		       <li>
    				 <div id="blog_title">
    		         <div class="blog_date"><?php the_date(); ?></div>
    		           <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></div>
    		           <p><?php the_excerpt(); ?></p>
    		       </li>
    	<?php endwhile; ?>

    its better to use posts_per_page as showposts is now deprecated – they do the same thing

    Thread Starter miowebdesigns

    (@miowebdesigns)

    Thank you, thank you …That was it.

    Thread Starter miowebdesigns

    (@miowebdesigns)

    One small issue if that the date is not showing up after the first post.

    I’m not seeing anything in the code that prevents the date from showing up in the second post. Check the browser source code and see if the div in
    <div class="blog_date"><?php the_date(); ?></div>
    appears. If not, you have to determine why not.

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

The topic ‘multiple "the Loop" not showing second posts’ is closed to new replies.