Display only One Single View Post in WordPress

February 2nd, 2009 § 1

Hey everyone,

I’ve come across a problem when building out a template where we need to display one post one the home page, but it needs to be a single view (so that it displays comments on that post) but cannot impact the query that shows a list of blog posts below. So, here’s a solution:

<?php $wp_query->is_single = true; ?>

    <?php $post_count = 0; ?>

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>    

        <?php if ($post_count == 0) : ?>

            <?php the_content(''); ?>

        <?php $post_count++; ?>

    <?php endif; ?>

<?php endwhile; endif; ?>

Below is a wireframe pic

Hope that helps – let me know if you have any questions.

Amendment:

I left something out, in order to display the rest of the posts I had to output an additional query. Something like the below code should work:

<?php $additional_posts - new WP_Query('cat=1'); ?>
<?php if ($additional_posts->posts) : ?>
<?php while ($additional_posts->have_posts()) : $additional_posts->the_post();  ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>

Tagged: , ,

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

§ One Response to “Display only One Single View Post in WordPress”

What's this?

You are currently reading Display only One Single View Post in WordPress at SilentGap.

meta