Questions tagged [get-template-part]

It is a WordPress core function that loads template parts inside theme templates. It makes it easy for themes to reuse sections of code like pagination, header images, menus, etc.

Filter by
Sorted by
Tagged with
4
votes
1answer
693 views

Is it safe/recommended to use wp_enqueue_script function outside the functions.php file?

I created multiple post formats, and when i use an audio post format, i want to include some additional javascript for the audio player. So, i include the content-audio.php like this: <?php ...
0
votes
1answer
310 views

Use a separate template for the home page only

I use Pinboard theme (it has a very complicated structure, but it is nice). Image how it works Select a template in this way it changes for all posts, pages, etc. and do not give you more choice. I ...
0
votes
4answers
988 views

How do I display an image before the first post of the loop when I'm using get_template_part?

I have used $count before, but never run into this problem. I cannot get it to work. I have limited php background, so please be patient with me! Here is the $count setup code: <?php $count = 0;...
1
vote
1answer
2k views

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. ...
9
votes
2answers
11k views

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' => '...
-1
votes
2answers
1k views

First post outside of loop, homepage only?

Because of the way my templates are structured, I need to pull the first/sticky post from the site outside of the standard loop, just on the homepage. I'm using _s (underscores.me) as a base, so the ...
3
votes
1answer
4k views

passing argument to get_template_part() or a better way to code

I have this include … event-list.php <?php /** * The loop that displays upcoming events */ ?> <ul class="event-items"> <?php $yesterday = time() - 24*60*60; $args = array( ...
2
votes
2answers
1k views

How to move style from template file to <head> section?

Imagine the following situation: //header.php contains: <header id="header">logo and navigation</header> //my-template.php contains: <?php get_header(); ?> <style type="...
0
votes
1answer
434 views

How do I get standard posts to open up in their own template when using get_template_part()?

It seems to me that twentyelven opens standard single posts using the file content-single.php yet when I try the same code and files they open for me in content.php here's the code I have in index....
27
votes
3answers
71k views

How to use get_template_part()?

Could someone please explain to me how this function works? I know what it does but when I look at the source code in the twenty_ten template, I don't get how all loops are being collected in one ...
1
vote
2answers
2k views

get_template_part and template file names

I have a custom post type that is going to use a loop in a couple different places and I wanted to make maintaining those loops easier. I remembered that get_template_part() is available and figured ...
0
votes
2answers
1k views

how to replace get_template_part('loop','tag') with explicit styled version?

So my theme has a tag.php, that contains this line: get_template_part('loop','tag'); that runs the loop and spits out the tag entries. I'm modifying it to include post thumbnails (using if(...
1
vote
2answers
1k views

get_template_part() - post-meta not working?

Maybe I simply do not understand what get_template_part() is doing … I have a file called event-list.php that should work as template for other pages and files so all my events (a custom post type) ...
10
votes
1answer
4k views

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 ...
0
votes
1answer
106 views

Taxonomy template for all taxonomies attached to certain post type

For instance, I have a product post type and I would like all the taxonomies associated w/ this type, such as size, color, material etc to display using the same template without having to 1. create a ...
1
vote
1answer
122 views

Unexpected results with conditionals inside template part

Scenario: I have a template part loop-product.php which i am calling from home.php, taxonomy.php and a page template template-products.php. Inside that template part loop-product.php file i am setting ...
0
votes
1answer
64 views

Custom fields in post later used in loop

How i can add custom fields to custom post templates, and later print them in The Loop? Better explanation: I want to have a custom field in "Add New" window, which will be added as some meta data to ...
0
votes
1answer
138 views

what template-part to call, to have my post in the center of the page?

i was wondering if you could help me : i would like to change the center of my page only with my posts : (all my posts will be in the same category) : how can i construct the page : so : 1.my menu ...
0
votes
1answer
2k views

how to modify request to get_template_part()?

i am modifying a P2 theme for a specific purpose, and it uses the get_template_part( 'entry' ) function to get the the whole entry html. What i then get is the who <li> element, but i want to ...
0
votes
2answers
821 views

Exclude function from homepage only?

There is a function in a theme that I am using that does some pagination stuff. I do NOT want that function to show up on my home page (only), so I'm trying to set up an if/else statement but can't ...
8
votes
2answers
13k views

How to make get_template_part always check child theme first?

How can I force WP to always check the child theme folder first when running get_template_part? Example: child theme loads get_template_part('content', 'inventory') in single.php. Because all child ...
0
votes
1answer
177 views

strange parse error when including a loop template within another template

I have a loop template called loop-event-details.php where I have code to display each event. My main page template is called events-page.php. I use the following code to include the loop template: ...
1
vote
2answers
493 views

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, ...
2
votes
1answer
707 views

Possible to use pagename inside get_template_part?

I'd like to grab the current page name and pull that specific template part per page. This way I can just set up a generic tier-1 template that calls in a secondary section based on the current page's ...
0
votes
1answer
2k views

Custom post type index (maybe using get_template_part)

I just created a custom post type "publication" with the slug "publications". Now im stuck trying to view all the publications index in a URL like: http://www.myExampleSite.com/publications Do I ...
15
votes
3answers
3k views

get_template_part vs action hooks in themes

It seems to me both of these afford the opportunity for the end user to modify a theme without actually editing the themes files (via child themes). My question is, is one method preferred over the ...