[wp-trac] [WordPress Trac] #41362: Make locate_template() filterable to change the template locations

WordPress Trac noreply at wordpress.org
Wed Jul 19 14:02:56 UTC 2017


#41362: Make locate_template() filterable to change the template locations
----------------------------+------------------------------
 Reporter:  kylejennings83  |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Themes          |     Version:  4.8
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:  template
----------------------------+------------------------------

Comment (by kylejennings83):

 @dingo_bastard Yes I know about the subdirectory for page-templates, but
 isn't that JUST for page templates, ie creating a page and selecting a
 special template for it?

 My solution allows a clean up of everything.  Another example I could have
 pointed out was using various filters to get all CPT templates (archive,
 single, ect ect) into a folder for that CPT.  For example, say you have a
 CPT called "movies".   By using:

 {{{#!php
 <?php
 add_filter('single_templates_path', 'move_movies_single_path');
 add_filter('archive_templates_path', 'move_movies_archive_path');
 }}}

 You could group all those related files together into a directory called
 "movies".  Now imagine that all your news/ blog posts were in a news
 folder, each section of pages had their own directory, ect ect.  Your
 theme would be so clean and easy to navigate.

 And thanks for the read, I guess I should change what I wrote but I just
 meant this would give people OPTION to organize their files into a MVC
 architecture.  So in my case, I usually just separate my logic and
 presentation with Timber.  So to expand on all these examples (but just
 moving/organizing the templates is enough ), youre theme directory could
 look like this:

 {{{
 /twentyseventeen/
 |-- /assets/
 |-- /inc/
 |-- /templates/
     |-- index.php
     |-- single.php
     |-- /team/
          |-- page-mortimer.php
          |-- page-biff.php
          |-- page-kyle.php
     |-- /news/
         |-- single.php
         |-- single-posts.php
     |-- /articles/
         |-- archive-aritcles.php
         |-- single-articles.php
     |-- /movies/
         |-- archive-movies.php
         |-- single-movies-kung-fury.php
         |-- single-movies-water-world.php
         |-- single-movies-pacific-rim.php
         |-- taxonomy-movie-genres-scifi.php
         |-- taxonomy-movie-genres-comedies.php
         |-- taxonomy-movie-genres-indie.php
 |-- /views/
     |-- index.twig
     |-- /team/
         |-- page-moritmer.twig
         |-- page-team-member.twig (used for all files in /template/team/)
 |-- functions.php
 |-- index.php
 |-- README.txt
 |-- rtl.css
 |-- screenshot.png
 |-- style.css
 }}}



 @SergeyBiryukov Thanks! I'm reading these tickets now, maybe we can merge
 things.  This ticket is a bit different because it follows the patterns
 set by #14310.  I'll comment in those tickets tho to see if anyone is
 interested in this one.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41362#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list