Opened 5 years ago

Closed 5 years ago

#7086 closed enhancement (fixed)

Look for Template Files in Stylesheet Directory First

Reported by: ThemeShaper Owned by: westi
Priority: normal Milestone: 2.7
Component: General Version:
Severity: normal Keywords: has-patch needs-testing
Cc:

Description

PROBLEM: I can make new, CSS-only, child themes by including "TEMPLATE:
define-parent-theme-here" in the comments of my stylesheet, inheriting all
the page templates of a parent theme. I can override and add new functions
by including a functions.php file with this child theme. BUT! What if I want
to add new page templates? Can I add foo.php or bar.php in the folder of my
child theme and make it available in WRITE > PAGE?

Nope, I can't. WordPress Should change this.

EXAMPLE:

sandbox
..header.php, sidebar.php, etc.
..links.php
..archives.php

Links and archives are existing custom template files

child-theme
..style.css
..functions.php
..foo.php
..bar.php
..header.php

foo and bar are new page templates that should become available in WRITE > PAGE when child theme is the active theme—but they currently don't. Plus, WordPress should use the header template from child-theme.

BONUS: Why would I want to do this? More custom themes, less work.

A blog is a blog is a blog: most custom theming work happens on the home
page. Make a new home-page.php file in a child theme and with some fun CSS
and javascript you can make a host of easily maintained themes; most of the
code is recycled from the pristine "parent theme". Imagine a hundred clients
with drastically different sites, all with easily upgraded code: overwrite
the parent theme, tweak home-page.php. Done.

This should also add a lot more options and possibilities to the coming
WordPress Theme Marketplace, speeding up theme vetting (most of the code
being inherited from The Sandbox) while providing some even more
dramatically new variations.

Attachments (9)

comment-template.diff.php (24.3 KB) - added by ThemeShaper 5 years ago.
theme.diff.php (20.8 KB) - added by ThemeShaper 5 years ago.
general-template.diff.php (39.7 KB) - added by ThemeShaper 5 years ago.
comment-template.diff (290 bytes) - added by KKWangen 5 years ago.
general-template.diff (1.0 KB) - added by KKWangen 5 years ago.
theme.diff (3.5 KB) - added by KKWangen 5 years ago.
7086.diff (6.9 KB) - added by ionfish 5 years ago.
7086.2.diff (7.7 KB) - added by ionfish 5 years ago.
7086.3.diff (419 bytes) - added by ionfish 5 years ago.

Download all attachments as: .zip

Change History (22)

  • Keywords needs-patch added

The category template can exist in two forms: a generic category.php file, and a category-$cat_id.php file. A number of other template calls follow the same pattern. What should the order of precedence be?

The child theme's category-$cat_id.php should clearly be looked for first, and the parent theme's category.php file last. However, it is not obvious which of the other two variations should take precedence over the other: the child theme's generic category.php file, or the parent theme's specific category-$cat_id.php file. My preference would be for the latter, but there may be dissenting views.

comment:2   andy5 years ago

ionfish: I echo your preference for checking for the same file in the parent before moving to the next file in the child.

I've probably attached these files incorrectly. Please forgive. I'm new here.

Anyway, the patch was coded by Kristin Wangen (http://wangenweb.com/). Child theme Template files can override parent theme files now. Unfortunately, neither one of us can figure out how to get new template files recognized. Anyone?

To be more specific; the trouble we got is that if you put a new custom page template into a child theme, the page template picker in write -> page don't "see" it.

The same goes for the theme editor, it only shows the template files for the parent theme.

I think it's tied up to $themes[$theme][Template Files] which both codes uses, but I'm not sure how to get around it.

+1

This would be an awesome feature for theme developers.

  • Keywords has-patch added; needs-patch removed

I've tried to upload new diff files based on the files from 2.6 RC1.

But I have still not figured out how to make WordPress recognize custom page templates in Child Themes.

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

ionfish5 years ago

Basically the same as the other patches, hopefully more easily applied.

ionfish5 years ago

  • Keywords needs-testing added

Updated patch, should now allow the use of custom page templates from both themes, as well as editing of same.

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [8497]) Look for template files in the stylesheet folder as well as the template folder for inheriting themes. Fixes #7086 props ionfish.

  • Resolution fixed deleted
  • Status changed from closed to reopened

A fix is needed for get_themes() which will now set a theme's 'Template Dir' to the name of the directory which happens to contain the first-listed file.

ionfish5 years ago

Not sure exactly what the patch achieves here.

Doesn't it just pick a different arbitatry file to get the directory from?

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in [8497], the directory that is checked in r9179 is the template directory of that file. Therefore it doesn't matter which file is chosen, it will point to the same base directory.

I haven't extended too much testing to it, but it appears to be the case.

Note: See TracTickets for help on using tickets.