homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

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

5+ Year Member



 
Msg#: 4441653 posted 9:13 pm on Apr 16, 2012 (gmt 0)

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

 

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4441653 posted 9:35 pm on Apr 16, 2012 (gmt 0)

Correction - undo the setting for showing the posts on the home page. Just use the code you've showen.

federico2005

5+ Year Member



 
Msg#: 4441653 posted 9:59 pm on Apr 16, 2012 (gmt 0)

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)

lorax

WebmasterWorld Administrator lorax us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4441653 posted 12:45 pm on Apr 17, 2012 (gmt 0)

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.

federico2005

5+ Year Member



 
Msg#: 4441653 posted 1:31 pm on Apr 17, 2012 (gmt 0)

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).

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved