0

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?

2 Answers 2

5

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
}
?>
1
  • 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 P
    Mar 5, 2012 at 14:32
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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