pagename.php template issues
-
Well, this took me a while to figure out what was going on, and I am still not sure WHY it is going on. Here’s the situation.
On older version of WP, I had pagename.php type page templates:
- Services page – page title Services, slug “services”, template file services.php
- News page – page title News, slug “news”, template file news.php
- …etc…
- About Us page – page title About Us, slug “aboutus”, template file aboutus.php
These ran in the template hierarchy in the pagename.php spot, no problems. The templates themselves are not identified as specific templates (no Template Name: templatename in comments at the top of the tile), are not chosen from the dropdown list of templates for each page. (I don’t want the client messing with what template is used for which page.)
And this worked fine. And where I was using the body_class tag, I would get page-template-services-php, page-template-news-php or page-template-aboutus-php. All was good.
And then I upgraded to 3.01. And I SWEAR it was still working yesterday. I could be wrong, but I swear it was all still as it was supposed to be when I was done yesterday converting the custom theme into a child theme of Twenty Ten.
Then today, while working on a different part of the site, I stumbled into the About Us page, and realize it was no longer using the aboutus.php template. It was, instead, using page.php. All of the other pages are still using their specific templates. The only difference between the about us page and the other pages is that the page name for the broken one has two words in it. So I started testing different things.
- Assigning a Template Name: About Us in comments at the top of the template file, then assigning the page to the About Us template in the appropriate dropdown, fixed the problem (but of course I don’t want to do this because I don’t want the client messing with assigning or changing templates).
- Naming the file about-us.php: does not work, nothing changes, still using page.php template.
- Renaming the page itself to About, with page slug of about, and template file name of about.php, still doesn’t work, and it still was calling page.php. What? Why would this setup work for Services/services/services.php, but not for About/about/about.php??
- Page Title About Us, slug aboutus, template page-aboutus.php (for the page-slug.php spot in the hierarchy): This works…it calls the right template file. But of course it changes the body_classes assigned. I now have page-template-default instead of page-template-aboutus-php or page-template-page-aboutus-php. I can of course use the page-id-20 class for applying the needed css, but still.
I’m using the last option at the moment, so things are working. But I’m REALLY confused about why I’m running into trouble in the first place. What am I misunderstanding?
The topic ‘pagename.php template issues’ is closed to new replies.