Support » Fixing WordPress » Display a specific post on home without page.php

  • Hello,
    I need to display a specific single post on my home page.
    I need to get it without using any home.php templates.

    As an example I need to display on my Front page the post ID 951 only.
    I set Blog pages showing at most 1 post in ‘Reading Settings’.
    Then I add the following code into index.php template:

    <?php while ( have_posts() ) : the_post(); ?>
    <?php if ( is_home() ) : ?>
    <? query_posts('p=951'); ?>
    
    <?php the_title(); ?>
    <?php the_content(); ?> 
    
    <?php else : ?>
    <?php endif; ?>
    <?php endwhile; ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>

    Unfortunately, my Front page displays 2 posts: that post (ID=951) and the latest post.

    Am I missing anything?
    Thanks

Viewing 1 replies (of 1 total)
  • I think this is what you want:

    <?php if ( is_home() ) :
       query_posts('p=951'); // Show only this post on home
       if (have_posts()) :
          while (have_posts()) :
             the_post();
             the_title();
             the_content();
          endwhile;
       endif;
    else:
       while ( have_posts() ) : the_post();
          the_title();
          the_content();
       endwhile;
    endif;
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Display a specific post on home without page.php’ is closed to new replies.