WordPress.org

Ready to get started?Download WordPress

Forums

Display a specific post on home without page.php (2 posts)

  1. placutus
    Member
    Posted 2 years ago #

    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

  2. vtxyzzy
    Member
    Posted 2 years ago #

    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;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic