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

Make a PHP file with a function

You really shouldn’t be doing this. Functions belong in the functions file. Period. (Or perhaps in a separate functions file which you include in the main one) However, if you insist, you can drop functions in any template file you want, because PHP doesn’t care. Actually you will need to include it in every template … Read more

Categories functions Tags breadcrumb, functions, get-template-part, templates

First post outside of loop, homepage only?

try and add this before your code: <?php if ( have_posts() && is_home() && !is_paged() ) : ?> <?php the_post(); ?> <?php get_template_part( ‘content’, get_post_format() ); ?> <?php endif; ?>

Categories wp-query Tags get-template-part, loop, sticky-post, wp-query

Print post data inside loop using theme content template

Every theme is different – there is no standard way of naming (or even using) a template part. You would be better off using your own markup and default styles, but allow theme authors to override it with hooks & filters.

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

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
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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