I built something like this:
Index Container Widgets Area
and I created a widget for that –
Categories Widget – Index Container .php
with this in:
<?php include (TEMPLATEPATH . '/includes/containers/container-grid-categories.php'); ?>
<?php ///include (TEMPLATEPATH . '/includes/containers/container-list-categories.php'); ?>
and for example in the
/includes/containers/container-grid-categories.php
is this:
<?php //include (TEMPLATEPATH . '/includes/containers/container-grid-categories/grid-thumbs.php'); ?>
<?php include (TEMPLATEPATH . '/includes/containers/container-grid-categories/grid-tumbs-details.php'); ?>
So, my questions, with this everything is working fine, the question is this a good way to make what I did (include TEMPLATEPATH)? Or use another way, and if that what way?
Thanks
2 Answers
Long answer short: the absolute-best answer, for template-part files in a subdirectory, is to use locate_template()
I would recommend referencing the stylesheet path for template file includes, so that those template part files can be easily over-ridden by Child Themes. So, ideally, you should use get_stylesheet_directory_uri()
.
Some differences/explanation of all the functions listed by @kaiser:
get_stylesheet_directory_uri()
/get_template_directory_uri()
return a URLget_stylesheet_directory()
/get_template_directory()
return a file path- All four of the
*get_*_directory_*()
functions perform SSL checking TEMPLATEPATH
/STYLESHEETHATH
are simple constants, return a file path, and do not perform SSL checking
So, the four get_*_directory_*()
functions are preferred to using TEMPLATEPATH
/STYLESHEET
; however, they aren’t really intended for locating template part files in subdirectories. In such a case, the best option is to use locate_template()
directly. (See here for a great writeup and comparison of all of the above options.)