Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

recent posts before page content WordPress

  • SOLVED

First off, I apologize, I am very new to this.
I am trying to display the 3 recent posts from a particular category before displaying content for the page. Using the code below I get the 3 recent posts and then where the page content should be displayed, I get the 3 recent posts again. What am I doing wrong?


<div id="recentposts">
<?php query_posts('posts_per_page=3&post_type=post&category=upcoming_events'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h5><?php the_title(); ?></h5>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>
</div>

<div id="pagecontent">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>

Answers (1)

2011-08-06

Christianto answers:

On between first query and second use
<?php wp_reset_query(); ?>

So it become:

<div id="recentposts">

<?php query_posts('posts_per_page=3&post_type=post&category=upcoming_events'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h5><?php the_title(); ?></h5>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>

</div>

<?php wp_reset_query(); ?>

<div id="pagecontent">

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>

</div>



Chad Seay comments:

That did it. Thank you!


Christianto comments:

You welcome Chad.. :D


Christianto comments:

Sorry, I mean you're welcome :D