How does get_template_part() work inside a loop?

Could someone please explain to me how this function works inside a loop? I’ve used this functions many times inside a wordpress loop like this: loop start get_template_part(“template/part”, “example”); loop end And the magic about this is that I can call functions like the_title() without any problem in template part-example.php. But if I try to … Read more

Why would include(locate_template) work but not get_template_part()?

The parent theme uses this construct to include the navbar: include(locate_template( “components/navigation.php” )); I would prefer to use the WordPress convention: get_template_part( “components/navigation” ); in my child theme, to call the file from the parent theme, but his code works and mine doesn’t. What am I doing wrong? UPDATE: The surrounding code looks like this: … Read more

TwentyTen: Overloading template.php files vs. get_template_part

I’m studying TwentyTen, under the assumption that it contains the best practices for writing themes and modifying them using child themes. I’m noticing what looks like a really redundant practice, which is to overload not the base template file (eg: attachment.php) but instead to overload the template-part file (eg: loop-attachment.php). Can someone explain the benefit … Read more

How to move style from template file to section?

Imagine the following situation: //header.php contains: <header id=”header”>logo and navigation</header> //my-template.php contains: <?php get_header(); ?> <style type=”text/css”>#header { display: none; }</style> <div class=”main-container-of-my-template”></div> <?php get_footer(); ?> This will disable <header> for my-template.php in the most modern browsers (except IE9) but it’s not valid solution. Is there a way to use something like wp_enqueue_style(); directly in … Read more

Template part vs Sidebar (differences)

I want to add a hard coded footer into the… footer.php of my site. This doesn’t need to be “dynamic” (adding and removing widgets), it will be something standard like info about the site and specific links. If I am correct this can be done either by get_template_part( ‘template-parts/’, ‘infofooter’ ); or by get_sidebar( ‘infofooter’ … Read more

Correct way to use get_template_part() and get_post_format() with custom post types?

I have a custom post type of ‘competitions’. In order to customise the display for this CPT in, for example, category listings I am doing the following: Create a category-competitions.php file Create a content-competitions.php file Within the loop in that file, call get_template_part(‘content-competitions’, get_post_format() )’ This works, but I’m not sure this is the correct … Read more

Template tags vs get_template_part() vs functions.php

When to use template tags and when to use get_template_part() and when to use function.php? I am confused at them. For example, if I want to show related portfolios under single portfolio, I can create a template tag named show_related_portfolios(). In contrast, I can create a file named content-related-portfolios.php, and use it like get_template_part( ‘content’, … Read more

Get template part based on custom taxonomy term

I have a custom post type and I’m trying to call up different variations of the navigation based on the custom taxonomy slug. I’ve done this fairly easily with normal posts, like so: <?php if ( is_category( ‘mixers’ )) { include (TEMPLATEPATH.’/nav-mixers.php’); } elseif ( is_category( ‘monitors’ )) { include (TEMPLATEPATH.’/nav-monitors.php’ ); } elseif ( … Read more

Passing variables to template parts

I have one template file videos.php which has the following line of code in it (aswell as a load of HTML): <?php get_template_part(‘loop’, ‘feed-videos’ ); ?> inside that template part, I have the following: <?php $video = ‘video-‘ . $post->ID; ?> <?php get_template_part( ‘include’, ‘modal-video’ ); ?> I would then like to be able to … Read more