Ticket #11216 (closed enhancement: fixed)
Support page templates located in a subdirectory of the theme
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.4 |
| Component: | Themes | Version: | 2.9 |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: | westi, dphiffer, rzen, info@… |
Attachments
Change History
comment:2
nathanrice — 2 years ago
I'll try to work up a patch for this. I don't think it wastes any execution overhead to include them, but just need to figure out a way to get the entire relative path included as the value, for instance, 'folder/file.php' or 'folder/folder/file.php' ...
- Cc rzen added
- Version set to 3.1
I'm jumping on board with this patch. We'll see how it goes
It looks like whatever was breaking the page template selector was resolved through another patch, because simply removing the lines from get_page_template() that prevent including subdirectories allowed everything to work as expected.
To accommodate the 'folder/folder/template.php' hierarchy that nathan mentions above (and that I would also like to use) I've modified /wp-includes/theme.php to loop through a second level. The variable names could probably be better. I also went ahead and added a filter of 'available_page_templates', at the suggestion of the ever-brilliant filosofo, to the output of get_page_template() should theme devs want to specify their own array of templates at an even greater depth.
Let the record show that this was my first attempt ever at patching core files. Review the patch at your own risk.
Does this work with child themes as well? That was the reason why we disabled it before.
Ah, nope. It works for templates nested in their parent themes, but not templates nested in child themes themselves. I'm uploading a new patch to extend the same directory depth for child themes as well.
- Keywords needs-testing added
- Type changed from feature request to enhancement
comment:10
scribu — 20 months ago
There's a lot of duplicated code there. Consider putting it into a helper function.
comment:11
scribu — 15 months ago
Related: #13265
-
attachment
11216.3.diff
added
Creates helper function for recursively searching through entire theme directory
comment:12
rzen — 7 months ago
- Version changed from 3.1 to 3.3
After 14 months, I finally worked up the courage to take scribu's advice and create a helper function. This function eliminates all the redundant code I introduced in 11216.2.diff as well as the repeated code from the original loops for collecting the template files.
With this patch, WordPress can support page templates in any level of subdirectory within a theme, both for parent and child themes, and not lose track of it's location.
I've personally tested it with page templates nested as deep as 2 directories for both a parent and child theme.
comment:13
SergeyBiryukov — 7 months ago
- Version changed from 3.3 to 3.1
Version field indicates when the enhancement was initially suggested.
comment:14
rzen — 7 months ago
- Version changed from 3.1 to 2.9
Ah, got it, I wondered about the redundancy between version and milestone. In that case, it is actually from 2.9.
Technically it's a bugfix, but I won't touch that dial. ...though, I'd really love to see this slink in to 3.3 because of it :)
comment:15
nacin — 7 months ago
Let's remove the code from theme.php rather than commenting it out. Also, $ignore should be = array() and we should array_merge() in .svn, .git, ., and .. -- there's never a reason for those to be searched.
At the same time, this is actually doing three loops through the directories, rather than two. Perhaps there's a better way to clear up the abstraction.
Definitely not 3.3 material, but could go into 3.4.
comment:16
nacin — 2 months ago
- Milestone changed from Future Release to 3.4
With WP_Theme, this is now an easy win.
comment:17
nacin — 2 months ago
- Owner set to nacin
- Status changed from new to closed
- Resolution set to fixed
In [20318]:
comment:18
follow-up:
↓ 20
toscho — 2 months ago
- Cc info@… added
There are some methods with @access public in PHPDoc while their visibility is set to private: _name_sort(), _name_sort_i18n() and scandir().
I think @access is obsolete when a visibility keyword is used in the method declaration.
comment:19
scribu — 2 months ago
Agreed. @access should only be used for private functions, since we can't use namespaces yet.
comment:20
in reply to:
↑ 18
nacin — 8 weeks ago
Replying to toscho:
There are some methods with @access public in PHPDoc while their visibility is set to private: _name_sort(), _name_sort_i18n() and scandir().
I think @access is obsolete when a visibility keyword is used in the method declaration.
I think I am going to make scandir() private, but _name_sort() and _name_sort_i18n() are public only because they are used as a callback. Their usage is private. Hence @access private.
You're probably right about @access not being necessary when a visibility keyword is in play. However, @access private specifically hides it from phpdocumentor and I am wondering if it overrides a visibility keyword.
Happy to remove @access private, and make scandir() private. New ticket?
comment:21
nacin — 8 weeks ago
Sorry, I got confused for a second there. _name_sort() and _name_sort_i18n() are indeed private, and can be since they are used by sort_by_name(). Their docs are wrong.
comment:22
nacin — 8 weeks ago
In [20324]:
comment:23
nacin — 8 weeks ago
In [20327]:
