Ticket #7086 (closed enhancement: fixed)

Opened 6 months ago

Last modified 1 month ago

Look for Template Files in Stylesheet Directory First

Reported by: ThemeShaper Assigned to: 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 (24.3 kB) - added by ThemeShaper on 06/07/08 03:55:06.
theme.diff.php (20.8 kB) - added by ThemeShaper on 06/07/08 03:56:04.
general-template.diff.php (39.7 kB) - added by ThemeShaper on 06/07/08 03:56:23.
comment-template.diff (290 bytes) - added by KKWangen on 07/13/08 20:25:10.
general-template.diff (1.0 kB) - added by KKWangen on 07/13/08 20:26:40.
theme.diff (3.5 kB) - added by KKWangen on 07/13/08 20:28:27.
7086.diff (6.9 kB) - added by ionfish on 07/29/08 22:16:57.
7086.2.diff (7.7 kB) - added by ionfish on 07/29/08 22:43:16.
7086.3.diff (419 bytes) - added by ionfish on 08/27/08 20:03:37.

Change History

06/03/08 19:38:54 changed by ionfish

  • keywords set to needs-patch.

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.

06/03/08 20:30:35 changed by andy

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

06/07/08 03:55:06 changed by ThemeShaper

  • attachment comment-template.diff.php added.

06/07/08 03:56:04 changed by ThemeShaper

  • attachment theme.diff.php added.

06/07/08 03:56:23 changed by ThemeShaper

  • attachment general-template.diff.php added.

06/07/08 04:02:32 changed by ThemeShaper

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?

06/10/08 06:20:09 changed by KKWangen

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.

07/04/08 13:13:01 changed by JohnLamansky

+1

This would be an awesome feature for theme developers.

07/13/08 20:25:10 changed by KKWangen

  • attachment comment-template.diff added.

07/13/08 20:26:40 changed by KKWangen

  • attachment general-template.diff added.

07/13/08 20:28:27 changed by KKWangen

  • attachment theme.diff added.

07/13/08 20:35:27 changed by KKWangen

  • keywords changed from needs-patch to has-patch.

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.

07/13/08 21:54:37 changed by westi

  • owner changed from anonymous to westi.
  • status changed from new to assigned.

07/29/08 22:16:57 changed by ionfish

  • attachment 7086.diff added.

07/29/08 22:17:37 changed by ionfish

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

07/29/08 22:43:16 changed by ionfish

  • attachment 7086.2.diff added.

07/29/08 22:44:12 changed by ionfish

  • keywords changed from has-patch to has-patch needs-testing.

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

07/30/08 06:21:14 changed by westi

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

08/27/08 19:56:01 changed by ionfish

  • status changed from closed to reopened.
  • resolution 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.

08/27/08 20:03:37 changed by ionfish

  • attachment 7086.3.diff added.

08/31/08 21:03:04 changed by westi

Not sure exactly what the patch achieves here.

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

10/15/08 03:17:04 changed by jacobsantos

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