Should we use get_template_part() in functions files instead of include_once?

Your functions.php doesn’t create output, so you should use locate_template(). Example: locate_template( ‘php/functions.nav-menu.php’, TRUE, TRUE ); You’ll find this function in wp-includes/theme.php. The first parameter is the file path relative to the theme root, the second tells WordPress to load it (or not), and the third to load it just once. Now a child theme … Read more

How to use get_template_part()?

Some very good introductory answers here. Basically, get_template_part() allows theme developers to set up an order of specificity of template files. Think of it similarly to specificity as it applies to CSS selectors. When designing something, you want to start with the bare minimum of specificity, so that it can be easily overridden in parts … Read more

Is there any way to use get_template_part() with folders?

In fact you can, I have a folder in my theme directory called /partials/ in in that folder I have files such as latest-articles.php, latest-news.php and latest-statements.php and I load these files using get_template_part() like: get_template_part(‘partials/latest’, ‘news’); get_template_part(‘partials/latest’, ‘articles’); get_template_part(‘partials/latest’, ‘statements’); Just dont forget to omit the .php from the file name.

Passing variables through locate_template

Like MathSmath wrote, get_template() does not support the re-use of your variables. But locate_template() infact does no inclusion at all. It just locates a file for inclusion. So you can make use of include to have this working just like you expect it: include(locate_template(‘custom-template-part.php’)); $var from your example can be used in the template part … Read more

Passing a variable to get_template_part

As posts get their data set up via the_post() (respectively via setup_postdata()) and are therefore accessible through the API (get_the_ID() for e.g.), let’s assume that we are looping through a set of users (as setup_userdata() fills the global variables of the currently logged in user and isn’t useful for this task) and try to display … Read more

techhipbettruvabetnorabahisbahis forumuedusedusedusedusedusedusedusedusedusedus