[theme-reviewers] get_template_part vs locate_template
Justin Tadlock
justin at justintadlock.com
Sat Apr 23 16:56:00 UTC 2011
get_template_part() was never meant to allow anything other than a slug
(not a directory and slug). Westi (who created the function) has stated
that this should be considered a bug. If you look at the inline
documentation for get_template_part() in the
wp-includes/general-template.php file, the documentation clearly states
that the first parameter of the function should be a *slug*.
Basically, get_template_part() is a generic version of get_header(),
get_footer(), and get_sidebar(). It's meant to work in a similar
fashion with the difference being that you can also define the slug.
There is a ticket trying to address the issue of sub-directories and
get_template_part() right now:
http://core.trac.wordpress.org/ticket/15086
Until that ticket has been closed and a resolution decided upon,
locate_template() would be the most correct option for including
templates within sub-directories.
Now, for the question of including CSS files, neither of the functions
should be used. CSS files must use the URI path, but those functions
will use the directory path. You should always use
get_stylesheet_directory_uri() or get_template_directory_uri()
(depending on the scenario).
On 4/22/2011 11:37 AM, Chip Bennett wrote:
> I believe the use of get_template_part() is acceptable for including
> files in subdirectories.
>
> However, CSS should *always* be enqueued and output via the
> wp_print_styles hook, rather than dumped directly into the template.
>
> Chip
>
> On Fri, Apr 22, 2011 at 11:34 AM, Curtis McHale
> <curtis at curtismchale.ca <mailto:curtis at curtismchale.ca>> wrote:
>
> I'm reviewing a theme and I've found uses of get_template_part
> where I believe that locate_template is the proper item.
> Specifically the code below loads the custom stylesheet.
>
> <?php get_template_part('css/custom-css')?>
>
> It was my understanding that in this case we should use:
>
> <?php locate_template( array( '/css/custom-css.css' ), 1); ?>
>
> and that get_template part was to call a file in the same
> directory like loop-main.php. Is there established best practice
> and if so what is it? Is the use above an okay way to call a
> custom stylesheet in to the theme? If not what way is currently
> advised?
>
> Curtis McHale
> PH: 604.751.3482
> http://www.curtismchale.ca
> Linkedin: http://www.linkedin.com/in/curtismchale
> Twitter: twitter.com/curtismchale <http://twitter.com/curtismchale>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> <mailto:theme-reviewers at lists.wordpress.org>
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110423/92246b3c/attachment.htm>
More information about the theme-reviewers
mailing list