0

I'm confused by the template hierarchy in WordPress. I have front-page.php in a theme I'm developing. It looks great and it works, but then when a user clicks 'Older Posts', it just shows the same content as before, but the URL is changed to ?paged=2.

Looking at the diagram about Template Hierarchy on Wordpress Codex, since the second page is not the front page, I'd expect it to fall through front-page.php to either home.php or index.php, but it's not doing that; it's just loading front-page.php over and over again.

So how can I load, say index.php, for every page other than the front page?

And also, am I crazy for expecting what I expect?

The second question might be subjective. Please only answer the first if you think I am crazy.

1 Answer 1

1

Pagination does not affect the template usually, paged.php is the exception but not of interest for your question.

To style the first page differently than later pages check for

if ( is_front_page() and 1 < get_query_var( 'paged' ) ) 
{ 
    // code for later pages
}
4
  • That's...rather hacky. I'd really like to have my "lists of posts" pages to look the same regardless where they are in the site. I.e. working off the same template. Doing what you suggest means the same code is in two spots. Yuck. Is there no other way? Oct 26, 2012 at 0:41
  • @ageektrapped - use a template part for code reuse.
    – Milo
    Oct 26, 2012 at 3:21
  • Thanks @Milo. I used your suggestion combined with toscho's to get what I wanted. Still think it's weird, but can't do much about it. Oct 26, 2012 at 13:31
  • @ageektrapped - you may also want to check out the template filters, which will let you force specific templates under your own conditions. look in wp-includes/template-loader.php and wp-includes/template.php to see how WordPress selects a template, and the apply_filters calls for each where you could add your own filter function to manipulate it.
    – Milo
    Oct 26, 2012 at 17:52

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.