Main Page – one post plus list of titles of other posts
I realize that problem was discussed many times on WP forum and few solutions’ were presented. The one I will describe here worked perfect for me. Actually the only one reason I publish it here is I want keep it in some visible place so I can use it whenever I need it ;).
Changes concern index.php file.
Here is original piece of code of Nigarila theme I use on this site:
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<div class="post">
<h2 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<p class="post-info"><em class="user"><?php the_author_posts_link() ?></em> on <em><?php the_time('M d Y'); ?></em> | Filed under: <em><?php the_category(', ') ?></em> <?php edit_post_link(); ?></p>
<div class="post-content">
<?php the_content('<span style="color: #990000">Continue Reading »</span>'); ?>
<?php wp_link_pages(); ?>
<p class="post-footer">
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
First I’ve replaced
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
with
<?php $my_query = new WP_Query('showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
Since new function uses ‘while’ loop and skips if condition I’ve changed <?php endforeach; ?> to <?php endwhile; ?> and removed <?php endif; ?>.
That allowed me to have one post displayed and at the same time not have it on the list below.
To create a list of titles of posts I’ve added below <?php endwhile; ?>
<h2>Recent entries:</h2>
<?php if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<div class="postlist" id="post-<?php the_ID(); ?>">
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> - <span class="post-info">Category: <em><?php the_category(', ') ?></em> on <em><?php the_time('d/m/Y'); ?></em></span>
</div>
<?php endwhile; endif; ?>
</div>
As you can see I’ve changed here a little way the post info is being displayed: first goes category, then publishing date (but in different format). I’ve skipped info on post author.
Entire piece of code I’ve put in place or original looks like that:
<?php $my_query = new WP_Query('showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
<div class="post">
<h2 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<p class="post-info"><em class="user"><?php the_author_posts_link() ?></em> on <em><?php the_time('M d Y'); ?></em> | Filed under: <em><?php the_category(', ') ?></em> <?php edit_post_link(); ?></p>
<div class="post-content">
<?php the_content('<span style="color: #990000">Continue Reading »</span>'); ?>
<?php wp_link_pages(); ?>
<p class="post-footer">
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
<?php endwhile; ?>
<h2>Recent entries:</h2>
<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<div class="postlist" id="post-<?php the_ID(); ?>">
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> - <span class="post-info">Category: <em><?php the_category(', ') ?></em> on <em><?php the_time('d/m/Y'); ?></em></span>
</div>
<?php endwhile; endif; ?>
</div>
</div>
Cool
; here are screenshots ‘before’ and ‘after’ (please, click on image to zoom it out).
![]()
1st October 2007 2 comments





Hi!
I’ve been looking to do this to a couple of long-term projects I’ve been working but I want to show lets say 3 posts and then have a list as such.
When I edit new WP_Query(’showposts=1′); to new WP_Query(’showposts=3′); it displays three but in the list below it duplicates the 2 extra posts I’ve tried to modify your code but I am getting know where any help?
Thanks Michael.
I’m using this same method to display the latest post and the excerpts of later posts. However, when I use the navigation to go back to older posts (blog.com/2/) it retains the latest post when all I want is a list of the previous posts. Any suggestions? Thanks!