mixmanner
Member
Posted 3 years ago #
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?
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:
http://codex.wordpress.org/Template_Hierarchy#Page_display
mixmanner
Member
Posted 3 years ago #
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!
bradleyg
Member
Posted 3 years ago #
This got me too. Maybe it should be added as a feature and then you won't need to change the docs!
bpopoff
Member
Posted 3 years ago #
Had a hard time with that too.
I agree for a rewording on the template hierarchy there : http://codex.wordpress.org/images/1/18/Template_Hierarchy.png
JoeCascio
Member
Posted 3 years ago #
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!
dmurphy
Member
Posted 2 years ago #
Beautiful. Thanks for the info!