Is there a variable for a template parts name?

One you have called a template with get_template_part() (or locate_template()) is there a way to know what template you are in. For example if you call get_template_part(‘loop’,’archive’); from archive.php and then are working in your loop-archive.php file. is there a way to define a variable that has the name of the current template part…. so … Read more

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

I’m using the theme-check plugin to check my theme for errors and recommendations, I’m using get_template_part() in theme files like header.php and index.php but in functions.php I’m using include_once() theme-check is not pointing at these, it’s pointing at include_once used in a widgets.php file which is included in functions.php my question is should we use … Read more

Is it possible to override the result of get_template_part()?

I’m working on a child theme, I strongly prefer not to override the main template files in order to maintain simplicity of the child theme as well as minimize the amount of code and maintenance over time. In the loop, the index.php template in parent theme uses: get_template_part( ‘content’ ); which will bring in content.php, … Read more

Using a custom WP_Query with get_template_part loop

I have a query for a custom post type: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $books = new WP_Query(array( ‘post_type’ => ‘wiki’, ‘posts_per_page’ => ’50’, ‘paged’ => $paged )); ?> And i want to loop through these posts using the loop-books.php: <?php get_template_part( ‘loop’, ‘books’ ); ?> Inside the loop-books.php i have these, … Read more

How to include a file using get_template_part() in a plugin?

A very simple question may be, but I’m struggling. In theme development, I worked with get_template_part() many times, and I understand its basics. But when I’s developing a plugin, I wondered using it showing me some errors: Notice: Use of undefined constant STYLESHEETPATH – assumed ‘STYLESHEETPATH’ in …\wp-includes\template.php on line 407 and Notice: Use of … Read more

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

I’m wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I’d like to put them in folders then. There is no information about that in Codex: http://codex.wordpress.org/Function_Reference/get_template_part 3 In fact you can, I have … Read more

Passing variables through locate_template

While I’ve typically used include or require on their own to save long term code maintenance I’ve started to use get_template_part and locate_template as using built in WordPress stuff is always best. My question is are you supposed to be able to pass variables through to the results of either get_template_part or locate_template? <?php $var … Read more

Passing a variable to get_template_part

The WP Codex says to do this: // You wish to make $my_var available to the template part at `content-part.php` set_query_var( ‘my_var’, $my_var ); get_template_part( ‘content’, ‘part’ ); But how do I echo $my_var inside the template part? get_query_var($my_var) does not work for me. I’ve seen tons of recommendations for using locate_template instead. Is that … Read more