WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#7086 closed enhancement (fixed)

Look for Template Files in Stylesheet Directory First

Reported by: ThemeShaper Owned by: westi
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch needs-testing
Focuses: 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 9 years ago.
theme.diff.php (20.8 KB) - added by ThemeShaper 9 years ago.
general-template.diff.php (39.7 KB) - added by ThemeShaper 9 years ago.
comment-template.diff (290 bytes) - added by KKWangen 9 years ago.
general-template.diff (1.0 KB) - added by KKWangen 9 years ago.
theme.diff (3.5 KB) - added by KKWangen 9 years ago.
7086.diff (6.9 KB) - added by ionfish 9 years ago.
7086.2.diff (7.7 KB) - added by ionfish 9 years ago.
7086.3.diff (419 bytes) - added by ionfish 9 years ago.

Download all attachments as: .zip

Change History (22)

#1 @ionfish
9 years ago

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

#2 @andy
9 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.

#3 @ThemeShaper
9 years ago

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?

#4 @KKWangen
9 years ago

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.

#5 @JohnLamansky
9 years ago

+1

This would be an awesome feature for theme developers.

@KKWangen
9 years ago

#6 @KKWangen
9 years ago

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

#7 @westi
9 years ago

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

@ionfish
9 years ago

#8 @ionfish
9 years ago

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

@ionfish
9 years ago

#9 @ionfish
9 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.

#10 @westi
9 years ago

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

#11 @ionfish
9 years ago

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

@ionfish
9 years ago

#12 @westi
9 years ago

Not sure exactly what the patch achieves here.

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

#13 @jacobsantos
8 years ago

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