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'm looking to display a list of posts in the header section on my template on all pages with the exception of the front page where I would like to show an image in place of the list of posts.

Is there a function within wordpress to detect the front page that I can use in my template code? or should I just be looking at PHP code that says if the URL matches X then show this, else show the other code?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

You can use the wordpress template hierarchy to do just that. Specifically, you can put the code you want in front-page.php and then use index.php for the rest of them, though that's a rather bland way of doing design with what you have on your hands.

Alternately, there are the wordpress conditional tags which can be used to detect whether you're on a category page or the frontpage, etc.

Edit

Using the is_front_page() conditional:

<?php
if ( is_front_page() ) {
    // This is the site front page;
    // put your front-page output here
} else {
    // Put your default output here
}
?>
share|improve this answer
    
The list will be shown in the header so the template hierarchy isn't an option. I'll have a look at the conditional tags. –  Vince Pettit Mar 5 '12 at 14:32
    
Conditional tags work perfectly thanks. –  Vince Pettit Mar 5 '12 at 14:45
add comment

Here are 2 ways you could do this:

  1. Create a page called home with your image in it (or use a custom page template with your image in it) then set that as your home page in the "Settings > Reading" section in the admin.
  2. Create a template file with your desired content and call it front-page.php
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.