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
1
vote
0answers
463 views

Modal working only on home page

I have created a modal pop up using JavaScript. The HTML for the modal is in a get_template_part("content","contact")` file. The issue is, only on the home page does the modal pop up Through a click ...
11
votes
4answers
6k views

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 ...
1
vote
1answer
241 views

Detect if current page is front page within custom query

I am currently working on a project where we're designing a custom frontpage template for a static front page. Within the template are three different custom WP_Queryies with relating loops. Within ...
4
votes
1answer
56 views

Get the php template file from other theme folder

How to get the php template file from other theme folder? For Example : My Current Theme Folder is promax . Im working on archive.php and want to include a template file inside of archive.php from ...
0
votes
2answers
5k views

get_template_part() based on get_post_type() for a custom post type instead of get_post_format()

I have custom post type of portfolio and I would like to be able to re-use most of the templating, but change to content-portfolio when the page is a custom post type named portfolio. At present this ...
0
votes
2answers
397 views

Remove get_template_part() from custom theme

I am creating my own theme and was wondering if there is a way to remove get_template_part() when you're on a specific page? For example: <?php if ( is_page('blog') ) { [Remove]get_template_part('...
2
votes
1answer
96 views

Is there a tirck in the get_xxxx function in the general_template.php file?

I'm a newbie in WordPress and I need a big help to understand how do-action works. It seems there is a relationship between the instruction do_action and the code that follows it in the get_xxx ...
0
votes
2answers
207 views

Display post order ranking within wordpress loop

I am trying to display the numerical post order ranking on the home page, however, I am using template_parts and am not aware of how to do this when the html is separated from the wordpress loop. ...
0
votes
1answer
92 views

Call get_template_part() custom permalink

How to call get_template_part() with custom permalink, I use childTheme from twentytwelve. In my theme I want to call popular post with get_template_part(). ex. If I call link http: //domain.com/...
5
votes
2answers
6k views

get_template_part from plugin

This is default get_template_part function inside WordPress: function get_template_part( $slug, $name = null ) { do_action( "get_template_part_{$slug}", $slug, $name ); $templates = array(); ...
2
votes
1answer
4k views

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 ...
0
votes
3answers
949 views

If I define a variable in header.php, how do I make it available to templates?

I've defined a variable in my child theme header.php. I'd like to get the value of this variable from one of the templates that is rendered after the request in which the header.php is called. So, ...
1
vote
3answers
250 views

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(...
0
votes
2answers
904 views

Tag page only display 10 posts

I've had a problem with this for quite some time now and cannot for the life of me figure it out. I am using Multi-site and not sure if that has anything to do with it or not, so keep that in mind. ...
0
votes
2answers
78 views

How do I make a variable available inside partials?

I've got a partial called within single.php that looks like this: <?php $userdata = get_userdata($post->post_author) ; ?> <div class="entry-meta"> <span class="byline ...
1
vote
1answer
241 views

Get template part using a custom taxonomy term

I've been using the following code to get a template part based on the parent term. It was working fine until I updated WordPress to v4.4 earlier today. Since updating if there is also a child term ...
50
votes
6answers
41k 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. ...
-1
votes
1answer
156 views

Print post data inside loop using theme content template

I am writing a plugin where I need to display the post data inside the loop using the theme content template in a page. It will be a similar page to the author profile page that displays a list of ...
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', '...
0
votes
1answer
525 views

Continue loop after $queryObject

Hi I'm using this code below to display five posts from a specific tag. Also the code allows me to stlye the first post different from the next four. <?php $queryObject = new Wp_Query( array( '...
1
vote
2answers
352 views

Does get_template_part pull data once in a loop?

When i use the "get_template_part();" inside a loop, does it search for that template file every cycle of the loop (each post) or does it search for the file once and then reuse it every cycle of the ...
0
votes
1answer
50 views

Both the require and add_template_part function are not including the file

I'm trying to add a require function in my functions.php, to include a file that is in the wp-content folder. I first tried this with the function content_url . 'filename.php'So the line of code ...
-2
votes
1answer
96 views

Make a PHP file with a function

I want to use the breadcrumb function as listed here: https://gist.github.com/melissacabral/4032941 Putting the code in functions.php works for me, but I would rather have it in a separate PHP file. ...
6
votes
4answers
2k views

Check if partial file is called from within header.php or footer.php

I am including a partial file both in header.php and in footer.php with get_template_part('content-form'); Is there an if clause I can use to check from where the file is being called? If it is ...
2
votes
2answers
82 views

Finding Page Template and Displaying Content

So, I'm building a theme for a client with one page layout functionality. Currently, I'm allowing the user to create a parent page, and the modules within that page are separate pages that will be set ...
2
votes
2answers
2k views

_wp_page_template to dynamically use template

I'm wondering if it is at all possible to set display a page template chosen by the user within the context of a query_posts using get_template_part. In other words, I have set up a page template to ...
1
vote
1answer
94 views

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, ...
1
vote
1answer
48 views

Is there any problem if I use get_template_part like this?

I want to display different content on my home page and in single pages, so I am using the following code in index.php: get_template_part( 'template-parts/content-home', get_post_format() ); At ...
0
votes
1answer
915 views

Displaying a custom post type using get_template_part into a specific layout

I am new to wordpress custom themes and am trying to recreate this website (http://www.divecarib.com/) as practice. I am trying to find the correct way to achieve the following: I have created a ...
1
vote
0answers
82 views

Loading template parts conditionally in Customizer

Here are my issues: I have layout options in customizer for full width or two columns. For fullwidth sidebar will not be loaded. The problem is if the setting is currently on full width when ...
0
votes
1answer
69 views

Does get_template_part() content gets parsed if it's not executed?

My page templates are currently built up as shown in first example but I really don't like that half of the template is just sitting there, not being used and takes the server resources for no good ...
0
votes
1answer
240 views

Include template file from plugin to theme

I am using a plugin in my theme options. I copied the entire plugin directory in my child theme directory and correctly included all the files in the theme functions.php. The plugin options files is ...
1
vote
1answer
580 views

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

Use another theme template in my theme

I want to use a different theme's portfolio page in my theme. I just want the content (portfolio layout of the other theme) but my own (active theme) header, footer, sidebar, and everything else. Is ...
0
votes
1answer
280 views

get_template_directory() returns wrong address on VPS

I'm having the following problem with a Wordpress installation on a VPS server. I'm trying to read from a JSON file but the returned address from get_template_directory() is wrong: $url = ...
0
votes
1answer
122 views

Get template part with CPT and Custom Taxonomy conditionals

I have two Custom Post Types Video and Gallery and a Custom Taxonomy Status with the term Featured. Right now I'm showing these CPT in my index.php, but I want to style each of them, so I'm using ...
0
votes
1answer
893 views

Check for the main query from the template

Besides the main loop in index.php, I'm calling several other custom queries across the theme, like this: $new_query = new WP_Query(array( // some args )); if ($new_query->have_posts()) : ...
0
votes
1answer
86 views

When using shortcode, content stops generating after the_content

Yesterday I implemented a shortcode, but now my comments and related posts stop appearing. The source of a rendered page now only displays <div class="posts-group"> &...
3
votes
1answer
10k views

Combining shortcode and get_template_part

I manage a wordpress site and have created a template part that I usually paste below the content. <div class="posts-group"> <h2>Featured store products</h2> &...
1
vote
1answer
660 views

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):...
0
votes
1answer
173 views

Get_template_part seems to be ignoring my template

I am developing a website that requires specific pages to have certain elements change color in addition to a full-width calendar page. I figured that using page templates and changing what ...
3
votes
1answer
15k views

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')...
0
votes
1answer
216 views

get_template_part doesn't output all data

I hope I get some help with get_template_part function. my starting point is a contact-us template (it's got map+address+emailform) that stores data in the database my other template is where I have ...
3
votes
2answers
2k views

Single Page Wordpress Theme - Using page templates

Well I am lost, its late and I have been searching google all night. Heres the problem I am running into. I am trying to create a singe page website using wordpress "pages". How I have initially setup ...
0
votes
1answer
2k views

Can't load search results with ajax

I'm trying to load search results on my page without reloading. I tried multiple approaches already, but I still can't make it work, despite using someone else's confirmed solution. Please find the ...
2
votes
2answers
3k views

How to pass variables with get_template_part?

I am developing a custom theme and i like to pass some variables to selected files. I am calling the view files from functions.php. $var1 = ; $var2 = ; etc include_once('form-views/view-profile.php')...
6
votes
4answers
7k 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 ...
0
votes
1answer
2k views

Get_template_part() problem with the_content()

I am creating one page wordpress theme - i am new to wordpress dev. The one page website have sections which represents pages. So every section on front page is page created via admin panel. There is ...
0
votes
0answers
882 views

Using require_once for parent-directory not working but is working in sub-directories

I'm building a custom theme and I'm attempting to use require_once __DIR__ . '/templates/variables.php' in my footer.php file, to keep from repeating code that contains variable information... I keep ...
0
votes
2answers
828 views

Get_Template_Part And Two Global WP_Query On Frontpage

I am working on a site where I use get_template_part to retrieve the loop. In the header of the template I specified so it runs the global query. global $user_ID, $wp_query, $pagename; Now, what ...