0

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.

1

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 } ?>
  • @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
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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