Forums

Two loops on page template - content spilling over into second loop? (2 posts)

  1. pavy
    Member
    Posted 3 years ago #

    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: http://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?

  2. pavy
    Member
    Posted 3 years ago #

    Found the solution.

    See this post: http://wordpress.org/support/topic/261677?replies=4
    See this site: http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

    And if you have trouble using the <!-- more --> tag when using get_posts():
    See this link: http://wordpress.org/support/topic/164560?replies=10

    And, finally, here is my new "loop" which is working, on a page template, set as my static home page:

    <?php
    global $post;
    $the_mini_posts = get_posts('numberposts=3');
    ?>
    
    <?php foreach($the_mini_posts as $post) : setup_postdata($post);  ?>
    	<div class="minipost">
    		<div class="minipost-words">
    			<?php
    			ob_start();
    			global $more;
    			$more = 0;
    			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 endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.