Welcome to WebmasterWorld Guest from 54.204.162.36

Forum Moderators: lorax & rogerd

display a specific post on homepage

displaying only a single post on homepage without using home.php template

   
9:13 pm on Apr 16, 2012 (gmt 0)

5+ Year Member



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
9:35 pm on Apr 16, 2012 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Correction - undo the setting for showing the posts on the home page. Just use the code you've showen.
9:59 pm on Apr 16, 2012 (gmt 0)

5+ Year Member



I did, but it does not work. I get the same result.

(anyway i had checked "Your latest posts" option for
"Front page displays" in 'Reading Settings'.
I had just set '1 post' when it comes to number of posts per page)
12:45 pm on Apr 17, 2012 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Have you set a static page for the home page? If all you want is to keep the same text on the home page - use a Page instead of a Post and tell WordPress to use a static page.
1:31 pm on Apr 17, 2012 (gmt 0)

5+ Year Member



no, I don't want to set a static page (I know how to do it with a new homepage template, but I don't want to use this option).
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month