Adding variable to get_template_part

It looks like you’re just trying to concatenate a string, so it can be done like this: <?php get_template_part( ‘template-parts/component-page/component-‘ . $variable ); ?> Or you could use string interpolation (note the double quotes used here): <?php get_template_part( “template-parts/component-page/component-{$variable}” ); ?> Alternatively, get_template_part() can take two parameters, $slug and $name: <?php get_template_part( ‘template-parts/component-page/component’, $variable ); … Read more

Show template loaded

The following will show the current template file to logged in admins only. If you add to the top of your functions file, you should see this info as the first line. add_action(‘wp_head’, ‘show_template’); function show_template() { global $template; global $current_user; get_currentuserinfo(); if ($current_user->user_level == 10 ) print_r($template); } You will still need to follow … Read more

Why aren’t my posts showing?

This doesn’t work the way you think it does because get_pages doesn’t do what you think it does. First, understand that all pages, all content, in WordPress is really a “post”. A “Page” is just a special type of post. Now, in a normal environment, you wouldn’t call “get_” anything. This is why you’re confused, … Read more

How can I get the content of the home page?

alternative to using the default loop in the front-page.php template: if( have_posts() ) { while( have_posts() ) { the_post(); the_content(); } } you could try using: if( get_option( ‘page_on_front’ ) ) { echo apply_filters( ‘the_content’, get_post( get_option( ‘page_on_front’ ) )->post_content ); } https://codex.wordpress.org/Option_Reference

Using “setup_postdata” with “get_template_part” does not work

For those who aren’t creating a query with get_posts() you may need to reference the global $post variable first before using setup_postdata(). Here is an example shortcode using a foreach loop and iterating through an array of post objects from an ACF Relationship field: function your_shortcode() { //reference global $post first global $post; $featured_posts = … Read more

How do you modify Page Template?

All code will be in the template. That is how custom templates work. Altering the output those templates is a code edit except where the templates have been written to include the post body, or meta fields, etc. But don’t go to Appearance->Editor and start hacking away. First, if this isn’t your theme you are … Read more