Articles of get template part

Using get_template_part to retrieve a template file based on current post type

I’m trying to use get_template_part to retrieve a template file based on the current post type (slug) the user is in. The template file just includes an image that is used specific to specific post types. <?php get_template_part(‘parts/get_post_type( $post )’) ?><p id=”t3-splash-title”><?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->labels->singular_name ; ?></p> The above doesn’t blow […]

How to localize inline script called with ajax

I have a loop of posts and I allow a user to edit each post using ajax. When the edit button is clicked for the post I use ajax to retrieve the template part containing the edit form for the post. Easy enough to do by creating a function with ‘get_template_part’ and then localizing a […]

get_template_part for each level of taxonomy term

before we start, thank’s for your time. Structure: cpt = corsi tax = argomenti tax_term = parent tax_term_child = child tax_term_child_granchild = grandchild Current code (on taxonomy-argomenti.php): $queried_object = get_queried_object(); $cpt = get_post_type( get_the_ID() ); $taxonomy = $queried_object->taxonomy; $term_id = $queried_object->term_id; $current_term = get_term_by(‘id’, get_query_var(‘term’), $taxonomy); if((int)$current_term->parent) get_template_part(‘argomenti’, ‘child’); else get_template_part(‘argomenti’, ‘parent’); I would choose […]

What is the best way to organize template parts?

I am trying to bring some order in to theme files and would like to separate templates parts. I see that underscore ( _s ) has done something similar but they moved only content templates inside , I have several templates for header , footer, content, portfolio, do you think that order like this would […]

How to get_template_part using AJAX?

I’m currently on the Woocommerce archive-product.php template file (say shop page or product category page). On the click of the post (or product), a GET query is added to the title of the same page, changing the page into a slider instead of a post list. I need to change the content of the page […]

Is there any way to get all the name or slug of template parts used in a page?

I am developing a custom plugin where I am using a single page template and changing the template parts only using ajax,I want to retrieve the template parts slugs or name (like custom-header.php, custom-footer.php, custom-sidebar.php, custom-profile.php etc). Is there any possible way to get all the template parts names which are used in a page […]

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 […]

Post Format single-loop.php using get_template_part

I have set up to use post formats gallery and video in addition to the standard. I am editing the loop-single.php to give it different layouts for each post format, but I’m to include get_template_part for each post format. This is what I have: <?php /** * The loop that displays a single post. * […]

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

Say for example you have a directory like this: theme – subfolder – template.php content-job-listing.php If I try and call get_template_part like so get_template_part(‘content’, ‘job-listing’) from the file template.php (note this is just a generic name not that actual name I’m using) it returns NULL. Similarly, if I use get_template_part(‘../content’, ‘job-listing’) this also fails to […]

Accessing $post variable from template part

Here is a section of code that I have in a template file — to display sub-navigation if the page has child-pages: <?php // display sub-nav if page has children ?> <?php $children = get_pages(array(‘child_of’ => $post->ID)); ?> <?php if (count($children)) : ?> <ul class=”nav nav-tabs”> <?php foreach ($children as $val) : ?> <li role=”presentation”> […]