Pass a variable to get_template_part

In category-about.php I have <?php /** * The template for displaying the posts in the About category * */ ?> <!– category-about.php –> <?php get_header(); ?> <?php $args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘about’, ); ?> <?php // important bit set_query_var( ‘query_category’, $args ); get_template_part(‘template-parts/posts’, ‘loop’); ?> <?php get_footer(); ?> and in template … Read more

get_template_part() does not work if you call it when you are in a subfolder

get_template_part() will work the same no matter where or how deep you are within your theme. It always includes relative to the theme (or child theme) root. So if you call the following from anywhere: get_template_part( ‘content’, ‘job-listing’ ); … it will try to load (in order): child-theme/content-job-listing.php parent-theme/content-job-listing.php child-theme/content.php parent-theme/content.php To load parts that … Read more

Too many get_template_parts?

In my opinion three or four calls of get_template_part() is perfectly acceptable and even within the norm for some of the larger and more complex themes out there. I don’t know how many is too many but I think it would have to be a pretty large number to notice a hit in performance. A … Read more

How to make get_template_part always check child theme first?

It does, by default. The get_template_part() function uses locate_template() which cascades through the template files in in order of specificity and stylesheetpath/templatepath. So, if your Child Theme includes a content-inventory.php, then get_template_part() will include it; if not, then it will look for content-inventory.php in the parent Theme. If it doesn’t find it, it will then … Read more

Is there a variable for a template parts name?

There isn’t a core global variable that returns the current context. However, you can construct your own, using contextual template conditional tags. You can step through the conditional tags in the same order as WordPress core, by following wp-includes/template-loader.php. Simply wrap your output in a custom Theme function. Here’s how I do it (note: I … Read more

tech