Ticket #7086 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

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

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

Change History

  • 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   andy4 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

ionfish4 years ago

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

ionfish4 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.

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

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

  • Status changed from closed to reopened
  • Resolution fixed deleted

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.

ionfish3 years ago

Not sure exactly what the patch achieves here.

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

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

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.