Support » Themes and Templates » Put multiple custom loops on same page

  • andrewrowland.g

    (@andrewrowlandggmailcom)


    I want multiple loops on my homepage, however only the first loop shows up. My homepage looks like this:

    <?php
    /*
    Template Name: Home
    */
    get_header(); ?>
    		<!--Four Columns-->
    	<hr>
    	<div id="content" class="twelve columns">
    
    			<div class="post-box">
    				<?php get_template_part('loop', 'land'); ?>
    			</div>
    
    		</div><!-- End Content row -->
    	<hr>
    
    		<!-- Row for main content area -->
    		<div id="content" class="twelve columns">
    
    			<div class="post-box">
    				<?php get_template_part('loop', 'home'); ?>
    			</div>
    
    		</div><!-- End Content row -->
    
    	<!--<hr>
    	<div class="tweleve columns.centered">
    	<div class="home-title-thoughts">
    	<h2>Our Thoughts</h2>
    	</div>
    	</div>-->
    	<hr>
    	<div class="row">
    	<div class="twelve columns">
    	<div class="home-quote">
    	<h3 style="margin-top:0px; margin-bottom:0px;">“Simplicity is the ultimate sophistication.”</h3>
    	<h4 style="margin-top:0px; margin-bottom:0px;">Leonardo da Vinci</h4>
    	</div>
    	</div>
    	</div>
    <?php get_footer(); ?>

    Here is loop-land:

    <?php
    	$counter = 1; //start counter
    
    	$grids = 3; //Grids per row
    
    	global $query_string; //Need this to make pagination work
    
    	/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
    	query_posts($query_string . '&caller_get_posts=1&posts_per_page=9');
    
    	if(have_posts()) :	while(have_posts()) :  the_post();
    	?>
    	<?php
    	//Show the left hand side column
    	if($counter == 1) :
    	?>
    				<div class="four columns">
    					<div class="postimage">
    						<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('home-thumb'); ?></a>
    					</div>
    					<h3 style="text-align:center;"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    					<p><?php the_excerpt(); ?></p>
    				</div>			
    
    	<div class="clear"></div>
    	<?php
    	endif;
    	?>
    
    	<?php
    	endwhile;
    	//Pagination can go here if you want it.
    	endif;
    	?>

    Here is loop-home

    <?php /* Start loop */ ?>
    <?php while (have_posts()) : the_post(); ?>
        <!--<h1><?php the_title(); ?></h1>-->
        <?php the_content(); ?>
        <?php wp_link_pages(array('before' => '<nav id="page-nav"><p>' . __('Pages:', 'reverie'), 'after' => '</p></nav>' )); ?>
    <?php endwhile; // End the loop ?>
Viewing 1 replies (of 1 total)
  • Thread Starter andrewrowland.g

    (@andrewrowlandggmailcom)

    Because I used query_posts your loop-land template is clobbering the main query. Don’t use query_posts. In loop-land I did this instead:

    $land = new WP_Query($query_string . '&caller_get_posts=1&posts_per_page=9');
    if($land->have_posts()) :  while($land->have_posts()) :  $land->the_post();

    What happens is that query_posts overwrites the main Loop and you loop over that. When you get to the have_posts part of the second loop, the post counter is already at the end. You’ve already Looped through the posts.

Viewing 1 replies (of 1 total)
  • The topic ‘Put multiple custom loops on same page’ is closed to new replies.