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
10
votes
1answer
3k 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 ...
4
votes
3answers
4k views

Variable use in get_template_part

As far as I understand (from the get_template_part codex) get_template_part is just a wrapper round the PHP require function. So if I have a variable that I have create in a page template file e.g. $...
1
vote
1answer
1k views

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 ...
1
vote
1answer
121 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
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 ...
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
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
2answers
1k views

wordpress header leaks into body in a specific template

very strange problem, that happens only in one specific template. part of the part "leaks" into the tag - and I can't figure out why. the "header.php" code: <!DOCTYPE html> <html lang="he"...
0
votes
2answers
758 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 ...
6
votes
2answers
12k 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 ...
6
votes
4answers
6k views

When is get_template_part() preferable to simply using the template.php files?

In this post on wordpress.stackexchange.com I asked whether using get_template_part(), as demonstrated in the TwentyTen theme, is a recommended best practice. The general consensus I got was that it ...
1
vote
2answers
483 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
693 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
173 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: ...
25
votes
3answers
63k 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 ...
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 ...
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 ...
3
votes
2answers
2k views

get_template_part inside get_template_part?

Ever tried this? // template file do_action( 'my_hook' ); // ex. functions.php function my_hooked_template_part() { get_template_part( 'my_loop_part_file', 'default' ); } add_action( 'my_hook', '...
49
votes
6answers
39k views

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. ...
14
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 ...