Support » Fixing WordPress » Template Hierarchy – Pagination – home.php overiding index.php

  • Hey Guys,
    I’ve noticed an inconsistency with the way template hierarchy works (IMHO).

    My theme has a home.php, which displays correctly on the sites homepage. But, when clicking through to “More posts” ( the template that is called is home.php, not index.php as expected.

    My reading settings are: Settings>Reading>Your latest posts

    My understanding is that home.php is only shown as the site’s homepage, meaning, the first page displayed. I don’t think /page/2/ should use home.php. Is this a bug, or is there a reason why it’s made like this?


Viewing 5 replies - 1 through 5 (of 5 total)
  • home.php trumps index.php in the template hierarchy.

    What you are seeing is the way it has always been. /page/2/ will use home.php as well. front-page.php may be what you are after, but you’ll need to set it as the front under Settings->Reading.

    If you want some code within either to display conditionally on the home page (ie the static front page or first page) use
    <?php if(is_home()) { ... } ?>

    Hey David,
    Thanks for that. It still seems unintuitive to me, but if that’s they way it is then that’s the way it is.


    OK, so how do I achieve this then? = template1.php = template2.php

    If I’m looking at:

    Would the conditional tag is_home be true? If so, what about on:

    I need a way to have the homepage be different than the pagination pages. I don’t want to have to set a static page as the front page, because the URL’s must stay as and

    Thanks for the help,

    This is UNTESTED, but it may work. Have your home.php choose which template to include:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if ( $paged == 1 ) {
      include(TEMPLATEPATH . '/template1.php');
    } else {
      include(TEMPLATEPATH . '/template2.php');

    Thanks vtxyzzy,
    I never tried you’re way, I got it working doing this before I saw your reply:

    <?php if (!is_paged()) {
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            } ?>
            <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>

    This is in my home.php file. Thanks anyway!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Template Hierarchy – Pagination – home.php overiding index.php’ is closed to new replies.