WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Having some trouble with template heirarchy. (8 posts)

  1. RollandRock
    Member
    Posted 4 years ago #

    Hi Guys,
    I recently started working on my first wordpress theme. It's for my friend's website, it's not completely done yet but I'm having some trouble with the template heirarchy.

    I set my homepage to a static page named home. The blog page is a secondary page. I made a custom blog.php theme page. I also made home.php for my front page.

    The problem I'm having is my blog page is loading home.php template and my home page is just loading the page.php template. I'm not quite sure what I'm doing wrong here, any insight would be really appreciated.

    The website is http://davidsawler.com

  2. RollandRock
    Member
    Posted 4 years ago #

    Actually, I just tried making a custom template for the contact page as well. It is also loading page.php for it's template. I do not know what I'm doing wrong here.

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    are you assigning the templates?

    All pages get page.php unless you assign them from within the edit page view

  4. RollandRock
    Member
    Posted 4 years ago #

    I actually got it work for my contact page (id 4) by making the page template page-4.php. This is not how I wanted to do it.

    When I go to edit page it says the only template I can assign is the archives.php file. Do I have to add something to the functions.php to allow it to notice these other templates?

    For my home I tried
    home.php
    page-home.php
    page-1.php

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    no...are you adding the appropriate header to the very top of each template?

    <?php
    /*
    Template Name: Contacts
    */
    ?>
  6. RollandRock
    Member
    Posted 4 years ago #

    Ahh, well that would be it. You're the man Voodoo! Thanks

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    glad we got it!

  8. TrishaM
    Member
    Posted 4 years ago #

    Actually, according to WordPress' own documentation, adding the custom template lines should not have been necessary for individual pages, as shown on this page.

    http://codex.wordpress.org/Template_Hierarchy

    It actually seems to be broken.

    On one installation of WP ver. 2.8.4, I have working home.php, as well as several other individual template pages like sitemap.php, contact.php, about.php, etc. They work perfectly because they match the page name, so they are used instead of page.php, without any additional statement at the top identifying them as custom template files, and no editing is needed in the Page either - so I just leave it as default template and WP knows which template file to use based on the page name.

    You only need to create a custom template, and use the lines supplied by RVoodoo at the top, if it's a template file you want to use across multiple pages which would not match either name, slug, or ID, to the template file. An example would be a set of pages where you want to call a different header, sidebar, or footer file.

    So RollandRocks attempts -

    For my home I tried
    home.php
    page-home.php
    page-1.php

    - should have worked perfectly too, in keeping with the normal template heirarchy spelled out in the Codex. The fact that it didn't indicates a broken installation.

    On another WP installation I have, of the very same version (2.8.4) the normal template heirarchy does not work.

    So the question remains, why not?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.