Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
12 views

Using same variable names in files added with get_template_part()

Say I have a file named content-header.php and content-body.php. In content-header.php I have this variable: $some_var = 'apples'; and in content-body.php I have a variable with the same name but ...
0
votes
0answers
47 views

Display a custom 404 page without a redirect

In a plugin I want to display a specific page without redirecting (and thus without changing the URL) like the plugin https://wordpress.org/plugins/404page/ does. I can capture 404s and redirect them, ...
1
vote
2answers
52 views

add a hook with get_template_part()

I have this hook. How i can add this hook with get_template_part()? I created a file "myfile.php" where I store the HTML code of my search bar, but a can't manage to connect my template add_filter('...
0
votes
0answers
17 views

get_template_part calls amount and performance?

I'm trying to build the theme that is easily customizable by other developers and chose to go get_template_part route so files can be easily overwritten in child theme. My question is there some ...
0
votes
1answer
24 views

Remove a short code and update it's content (AJAX)

This is my code function ajax_layoutcontrol(){ if( !check_ajax_referer( 'special-string','security')){ return wp_send_json_error( 'Invalid nounce'); } if (! current_user_can('...
0
votes
1answer
40 views

How to get value from radio buttons meta box, and return different contents?

I have a multiple checkbox type question (using Ultimate member) storing values as user meta. The question basically asks the user what he wants, and according to what he wants, I would like my ...
1
vote
0answers
28 views

Styles and scripts inside template part

Is there anything wrong with including style and script tags inside a template part? The template part which I'm using like something more similar to a vue/react component is working correctly but ...
2
votes
1answer
86 views

Problem with using get_template_part() in footer

First off let me just say, I'm new to theme development, I hope there isn't something obvious I'm missing. I'm trying to get this form contactform.php <form method="POST" action=""> <...
2
votes
1answer
49 views

how to remove get_template_part from a plugin? [closed]

I have a template file and that file has two get_template_part(). ie,get_template_part( 'store' ); get_template_part( 'header' ); these two are used inside a template page, I wanted here to ...
0
votes
1answer
192 views

get_template_directory_uri() not working

I am getting trouble with the following lines of code. Actually I have created a custom file confirm_email.php in which I wrote the following piece of code. When I'm removing $temp_dir variable it ...
0
votes
1answer
398 views

How to reuse get_template_part() containing a simple loop to work with AJAX correctly?

I've got simple loop in standard-loop.php file (which, the file, is located in inc/loop folder): if ( have_posts() ) : while ( have_posts() ) : the_post(); the_content(); ...
0
votes
2answers
210 views

How can I show contents of a template part inside of another page?

Wordpress is of course made up of templates and the template parts that make up those templates. I know I can override the template parts - that's not what I'm trying to do here. I'm trying take the ...
1
vote
1answer
34 views

How to show “teaser” posts on blog / archive pages, otherwise full posts

Forgive me, I'm a PHP noob and writing too much of it makes my eyes glaze over; I'm sure this is a super simple solution and probably a dumb question. I'm working on a custom theme where I want to ...
0
votes
1answer
50 views

How to limit the number of Related Posts?

In my theme's file single.php, there is this part of code to get Related Videos: <?php if ( $wp_query ->have_posts() ) { while (have_posts()) : the_post(); ...
0
votes
2answers
81 views

get_template_part causes 500 error

I am trying to list posts in a widget I am working on at the moment. However, when I use the get_template_part function in my loop, my site just keeps loading until I get a 500 http error. $args ...
1
vote
1answer
192 views

Modify foreach loop for social sharing links?

How would I amend the following foreach loop so each link displays the keys from each nested query, and not just the values? I am creating my own social sharing links, included using get-template-part,...
0
votes
1answer
50 views

Insert template-part inside the content

I want to display an image/banner with link, inside the content of the posts of my blog. Neither at the beginning, nor at the end. It should appear somewhere inside the content of the post. I don't ...
0
votes
1answer
53 views

How to create new template page and template-parts in wordpress theme [closed]

I want to create custom form page to communicate with database with my own table. I written this code, But its not showing in page attributes template. My Template Code: <?php /*Tempalte Name: ...
2
votes
0answers
27 views

Unable to include a template

On the home.php, which is in the same folder where style.css is kept I am try to call a template: <?php get_template_part( 'template-parts/content', 'home-default' ); ?> template-parts is a ...
2
votes
1answer
501 views

get_template_part execute with ajax

I would like to get template part with AJAX. This template part - more-images.php contain of source some wp php and html. I read AJAX is build in WP. So I put code below to my theme files. My code: ...
0
votes
1answer
413 views

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

get_template_part - how to find html file which is being render

I am new to Wordpress I can see following file <?php get_template_part( 'template-parts/header/site', 'branding' ); ?> But I am not able to find the file which is being rendered here in ...
0
votes
2answers
115 views

How to use template inside plugin shortcode with variables for big HTML code

I have a shortcode which will have a big HTML. It will have 4 selects which I'm getting the data inside the shortcode: $house_types = get_terms(array( 'taxonomy' => 'house_types', 'hide_empty'...
0
votes
1answer
33 views

Select through customizer the template part to be viewed

I plan to make one-page website in which any section of the page can be chosen by the Admin to be displayed or not. I've seen in some themes that it is possible to turn off some template parts to hide ...
2
votes
1answer
1k views

get_template_part not working with ajax

I loaded some contents by ajax, When i try something like this: $resp = array( 'success' => true, 'data' => 'the content here' ); it's working without any issues but if i used ...
0
votes
2answers
198 views

How to use get_template_part always relatively to the file I'm using it in?

I have the following file structure (simplified): — app — header.php - views - header-default.php In header.php, I'm using get_template_part as follows: <?php get_template_part( 'app/...
1
vote
1answer
295 views

How to make get_theme_mod work with AJAX in the customizer preview

Is it possible to make the get_theme_mod work after refresh in the customizer preview pane when it's being called inside a template part by AJAX? I have a theme that loads the posts on scroll (...
0
votes
1answer
58 views

Templates & CSS - Proper Programming Practice?

I've worked with WP/html/css casually for a long while but never dug deep before, I have a few questions about good practices. My Background - totally skip this if uninterested I've been left ...
0
votes
1answer
103 views

Looking to load a different template part on every load/refresh

I basically have a site where I have several different template headers that I want to load via get_template_part. The basic idea is when someone first visits the site, they should see a random ...
1
vote
2answers
2k views

Pass a variable to get_template_part

In category-about.php I have <?php /** * The template for displaying the posts in the About category * */ ?> <!-- category-about.php --> <?php get_header(); ?> <?php $args =...
1
vote
1answer
585 views

get_template_part based upon post's category

I have a WordPress website setup with 5 main parent categories each with dozens of child categories For each WordPress post in single.php, I'd like to load some content based upon each child category ...
1
vote
1answer
816 views

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

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

get_template_part() Not Working in Loop

I am having trouble getting get_template_part() to work on my index.php page. The template part is in the loop and is referencing a 'standard' post format. template code: <section id="content" ...
1
vote
0answers
373 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 ...
1
vote
1answer
212 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
54 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
4k 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
328 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('...
6
votes
5answers
1k views

How to add custom content template part for a custom post type on main query using a plugin

I have a custom post type paper defined in my WordPress plugin that I show along with standard posts in the main query via: function add_custom_post_types_to_query( $query ) { if ( is_home() &...
2
votes
1answer
89 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
176 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
84 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/...
2
votes
1answer
3k 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
585 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
135 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(...
-1
votes
1answer
127 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 ...
0
votes
2answers
66 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 ...
0
votes
1answer
447 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
295 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 ...