Two loops on page template – content spilling over into second loop?
-
I am using a page template which I made to show the page’s content (this is a WordPress page, I made from a template) and to also show the most recent 3 posts. The loop for the recent 3 posts works as it should, however, in the template I have another loop after the 3 posts loop, to show that page’s content. For some reason, the posts are showing up in that loop and I’m not sure why or how to fix it.
Here is the loop I’m using for the recent 3 posts:
<?php query_posts('showposts=3'); global $more; $more = 0; if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="minipost"> <div class="minipost-words"> <?php ob_start(); the_content(__('(more...)')); $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents()); ob_end_clean(); echo $postOutput; ?> </div> <?php echo get_the_image(array('default_image' => '/wp-content/themes/palershadeofgray/images/default_thumbnail.jpg')); ?> </div> <?php endwhile; endif; ?>
And here is the loop I’m using after the above, to show the content for this page (again, it’s a Page I made in WordPress admin, using the Pages):
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="words"><?php the_content(); ?></div> <?php endwhile; endif; ?>
Here is a link to see it happening: https://wordpress.matthewpavkov.com/
What should be happening: You should see the most recent 3 posts on the right side (this is working), and in the main content area, you should see a single line which reads “This is the home page”. Why are all the posts showing up there? I also have this page set as the static home page, but this doesn’t make a difference, I tried the page without having it set as a static home page. When I take out the first loop (for the recent 3 posts), then the page’s content shows up as it should.
Suggestions?
- The topic ‘Two loops on page template – content spilling over into second loop?’ is closed to new replies.