[wp-trac] [WordPress Trac] #15086: get_template_part() should let you specify a directory

WordPress Trac wp-trac at lists.automattic.com
Mon Oct 11 07:16:35 UTC 2010


#15086: get_template_part() should let you specify a directory
---------------------------+------------------------------------------------
 Reporter:  aaroncampbell  |       Owner:             
     Type:  defect (bug)   |      Status:  new        
 Priority:  normal         |   Milestone:  3.1        
Component:  Themes         |     Version:  3.0        
 Severity:  normal         |    Keywords:  needs-patch
---------------------------+------------------------------------------------
Changes (by westi):

  * keywords:  dev-feedback => needs-patch
  * type:  enhancement => defect (bug)
  * milestone:  Awaiting Review => 3.1


Comment:

 Replying to [comment:7 Viper007Bond]:
 > Replying to [comment:6 westi]:
 > > It looks like @Viper007Bond added the directory example to the codex
 :-(
 > >
 http://codex.wordpress.org/index.php?title=Function_Reference/get_template_part&diff=92384&oldid=90074
 >
 > I added it as a WP.com VIP did it and I thought it was a clever
 organizational method. I didn't realize it wasn't intentional to allow
 such a thing. :)
 >
 > Personally I really like the idea of it though. Say for example you have
 a bunch of ad template parts. Rather than having to clutter up the main
 directory, you can just make an "ads" folder and stick all your ad
 templates in there.
 >
 > We shouldn't break backwards compatibility by not allowing slashes in my
 opinion. Perhaps we can deprecate it though in favor of an additional
 argument so that `get_template_part( 'banner', false, 'ads' )` will look
 for `/ads/banner.php` and then `/ads-banner.php` or something.
 >
 > Or maybe we just leave it as is with some better security (probably the
 best).

 Thank you for illustrating the use case.

 I guess it would be nice to switch to encouraging the directory to be a
 separate argument but preserving support for the old method.

 Whatever a bit of an extra security blanket would be worth having although
 I hope people are not taking user submitted data and passing it to
 get_template_part ;-)

 I like the idea of switching to adding a folder argument so that child
 themes can override simply but dropping in a file in the root and not have
 to worry about recreating the folder structure.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15086#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list