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
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*get_*_directory_*()
functions perform SSL checkingTEMPLATEPATH
/STYLESHEETHATH
are simple constants, return a file path, and do not perform SSL checkingSo, the four
get_*_directory_*()
functions are preferred to usingTEMPLATEPATH
/STYLESHEET
; however, they aren’t really intended for locating template part files in subdirectories. In such a case, the best option is to uselocate_template()
directly. (See here for a great writeup and comparison of all of the above options.)There are several way to acchieve this: