Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;">&#8220;Simplicity is the ultimate sophistication.&#8221;</h3>
    <h4 style="margin-top:0px; margin-bottom:0px;">Leonardo da Vinci</h4>
    </div>
    </div>
    </div>
<?php get_footer(); ?>

Here is loop-land:

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

Any ideas on how to fix this?

share|improve this question
2  
Are you referring to the 2 loop templates? You'd need to show the code in those files. –  vancoder Apr 22 '13 at 19:01
    
Please include the loop code in your question. –  t f Apr 22 '13 at 19:01
    
@vancoder I added the loop codes. –  drewrowalnd Apr 22 '13 at 19:04
add comment

1 Answer

up vote 2 down vote accepted

Because you used query_posts your loop-land template is clobbering the main query. Don't use query_posts. In loop-land do 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.

share|improve this answer
    
Perfect! Thanks. –  drewrowalnd Apr 22 '13 at 19:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.