eatanicecream
Member
Posted 2 years ago #
Hi everyone
I'd like to set up a home page in such a way that it shows the main content of the page along with the excerpt of the two last blog posts from the blog page.
I've used <?php the_content('Read the rest of this entry »'); ?> to show the main content of the 'home' page and this works.
But how do I pull in the two latest blog posts? I tried putting in the loop, but that showed the main home page content (so that I had it twice). I also tried replacing <?php if (have_posts()) : ?> with <?php rewind_posts(); ?> as described in the multiple loops section of the Codex. This did nothing.
Is multiple loops the way to go? If so, what am I doing wrong?
You have to set up a 2nd query & Loop for your posts using query_posts or get_posts.
eatanicecream
Member
Posted 2 years ago #
Hmm...can't get it to work. Do you have an example?
<?php
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 2,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
// the_content();
// the_excerpt();
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
eatanicecream
Member
Posted 2 years ago #
Figured it out. I used:
<?php query_posts($query_string . '&cat='); ?>
<?php while (have_posts()): the_post(); ?>
<h3><a href="<?php the_permalink(); ?>" title="Read full post"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<?php endwhile; ?>