Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

get-template-part

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

It the template is called via get_template_part(), then it is in a new variable scope. to access it, you have to use the global keyword in you template file: global $foo; echo $foo; As header.php probalbly is also called in a function scope, you have to make sure there the variable is used in global … Read more

Categories PHP Tags child-theme, get-template-part, php, templates, variables

strange parse error when including a loop template within another template

I’ve created a new file, specified the encoding as “UTF-8” and retyped everything by hand – no copy/paste from the old file. Took a while, but all works now. It must have been some encoding errors playing up. Thanks to everyone who helped: @t31os, @kaiser, @Chip Bennett

Categories loop Tags errors, get-template-part, include, loop

wordpress header leaks into body in a specific template

Can you be a little more specific on which part is ‘leaking’ into the body? It’s hard to tell without running any code and having other parts of the theme to look at.

Categories page-template Tags get-template-part, headers, page-template

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

In the Twenty Ten theme they are using a file called loop.php. It defines the loop for different page templates and defines theme accordingly inside loop.php. That’s what allows them to use get_template_part. Depending on your theme and how it’s set up will determine how to go what your asking. If all of your pages … Read more

Categories posts Tags get-template-part, loop, posts

how to modify request to get_template_part()?

Just looked in the P2 theme files. The theme loads the entry.php with the function p2_load_entry() located in inc/template-tags.php. If you want to edit the entry.php file and want to be on the safe side if P2 releases an update, you should create a Child Theme. Create a new sub-folder inside wp-content/themes/ e.g. p2-child Inside … Read more

Categories customization Tags customization, get-template-part, theme-p2

Taxonomy template for all taxonomies attached to certain post type

the answer is yes, yes i can. do love it when i find the answer w/in minutes of posting here. add_action(‘template_redirect’, ‘my_template’); function my_template() { if ( is_tax() && in_array(get_query_var(‘taxonomy’), get_object_taxonomies(‘product’) ) ){ include (get_stylesheet_directory(). ‘/product_taxonomy.php’); exit; } }

Categories taxonomy Tags get-template-part, taxonomy, templates

query_post while (have post) get_template_part()?

query_post while (have post) get_template_part()?

Categories custom-post-types Tags custom-post-types, get-template-part, pages, templates

How return normal search result using wp_ajax action for wordpress

You can try to store $wp_query in a cookie or in a session variable. global $wp_query; setcookie(‘my_wp_query’, $query_string); or global $wp_query; $_SESSION[‘my_wp_query’] = $query_string; and use that in you ajax function.

Categories wp-query Tags ajax, get-template-part, wp-query

get_template_part() to render single page Theme

Something like this if you want to call mytemplate.php: get_template_part( ‘template’); Or something like this if you want to call content-mytemplate.php: get_template_part( ‘content’, ‘mytemplate’ ); I hope that this will help you.

Categories loop Tags get-template-part, loop, page-template, pages

Is this correct get_template_part() in WordPress?

I think you have to enter the_post();, after have_post(),for more information on get_template_part(); refer to codex

Categories PHP Tags get-template-part, php
Older posts
Newer posts
← Previous Page1 Page2 Page3 … Page21 Next →
+ More

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
Next Page »
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress