• I’m sure I’m doing something ridiculously obviously wrong, but I’ve never been able to get the uppermost level of the template hierarchy for pages to work. As I understand it, the hierarchy is:

    pagename.php -> page.php -> index.php

    So I would think that if I had a page named Articles and I put an articles.php file in the theme folder, it would use that as the template by default. But the only way it works for me is if I put that special Template comment at the top of the file, and then edit the page in the backend and select it as a template.

    Anyone know what I’m doing wrong?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    No, the “pagename” is just filler. What it’s meant to be describing is a Page Template.

    A Page Template can actually have any name, but it does need this at the top of the page:

    <?php
    /*
    Template Name: Whatever the name is
    */
    .. rest of page template here

    Then, when you go to Edit the actual page, you’ll find a drop down box for Page Templates, and there you can assign what template should be used for the Page.

    It doesn’t actually look for “articles.php” for a page named “articles”. perhaps it’s explained poorly in the documentation.

    See here:
    https://codex.www.ads-software.com/Template_Hierarchy#Page_display

    Thread Starter mixmanner

    (@mixmanner)

    Ah, okay. Well at least I’m not crazy. I’ve made a lot of WordPress sites and could never get that to work, and always thought I must be doing something wrong.

    I think the documentation and template hierarchy image could probably use a bit of rewording to make it a bit clearer. I can’t imagine I’m the only one to make that mistake . . . although I couldn’t find anything on the forums about it so maybe I am.

    Anyways, thanks for your help!

    This got me too. Maybe it should be added as a feature and then you won’t need to change the docs!

    Had a hard time with that too.
    I agree for a rewording on the template hierarchy there : https://codex.www.ads-software.com/images/1/18/Template_Hierarchy.png

    Ditto. It really needs an example. You could never figure that out from the existing doc. There’s nothing in there about the pagetemplate and the comment that has to be in there.

    I wouldn’t have figured it out if not for this page. The template heirarchy needs to be revised!

    Beautiful. Thanks for the info!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘pagename.php has never worked for me’ is closed to new replies.