Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a page called 'home' which is set to be the front of my site, but I'd like it to show the most recent blog post or two at the bottom. I have some PHP that will do this from another site

<?php 
query_posts('showposts=1');
while (have_posts()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content('Read the rest of this entry &raquo;'); ?>
<p><a href="<?php echo $siteroot .'/blog/' ?>">Go to the Blog...</a></p>
<?php endwhile; ?>

But I'm not sure where to put it in order to make it so it only shows on this one particular page since is_home() returns false for the page.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Since you are saying it's a "Page", I believe you should try is_page instead of is_home:

<?php
    if ( is_page( 'about' ) ) {    
         // Code to be shown on Page whose slug is "about"
    }
?>

OR for the way your code is, this should do:

<?php if ( is_page( 'about' ) ) { ?>
    <!-- Code to be shown on Page whose slug is "about" -->
<?php } ?>
share|improve this answer
    
perfect! thank you :) –  Damon Jul 2 '12 at 2:32
    
@Damon then you should "mark" it as the answer :) –  its_me Jul 2 '12 at 2:37
    
word dawg, but it makes me wait 10 minutes ;) –  Damon Jul 2 '12 at 2:45
add comment

You can display code on a page set as the front page of your site using 'is_front_page' instead of 'is_home'. Any page set as the front page under Settings->Reading->Front page displays will then show the content within the query, instead of relying on a specific page slug.

http://codex.wordpress.org/Function_Reference/is_front_page

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.