Including template pages within another template?

The function get_page() has been deprecated, don’t use it anymore, use get_post() instead. get_page_by_title() returns an object by default, you can change this by altering the $output parameter, which you can use like you did. Although get_post() can take an object as $id parameter I personally prefer inputing the ID, but that actually shouldn’t matter. … Read more

Use of IF statement in Header file

As Maruti Mohanty mentioned you might not be using get_template_part in the correct way. The first argument is the slug name for the generic template. The second argument is the name of the specialized template. So currently your code is doing the following: On the page that has the ‘custom-page’ slug, display the template part … Read more

How can have a conditional template tag based on the main loop within a secondary loop with new WP_Query(), using get_template_part()

You can ask the main query directly (which is, in fact, exactly what the is_front_page function is doing). <?php global $wp_query; ?> <?php if ( $wp_query->is_front_page() ) : ?> <div><?php the_content(); ?></div> <?php endif; ?> If you altered the main query, however, refer to the backup. <?php global $wp_the_query; ?> <?php if ( $wp_the_query->is_front_page() ) … Read more

Problem with Front-Page.php loading recent posts

You have to reset every instance of a custom query, otherwise you will get unexpected output from any other query there after Simply use wp_reset_postdata() after every custom query. Example <?php $args = array( ‘numberposts’ => ‘1’, ‘meta_key’=>’_thumbnail_id’ ); $recent_posts = wp_get_recent_posts( $args ); foreach($recent_posts as $post) : ?> <?php get_template_part( ‘content’, ” ); ?> … Read more

Is there a way to retrieve the calling template part?

After finding this answer, I went with: $template_tree = mytheme_get_template_tree(); $total = count($template_tree); //count the elements in the array end($template_tree); //set the pointer to the end of the array $immediate_parent = basename(prev($template_tree)); //get the filename of the penultimate element Then in a plugin / functions.php function mytheme_get_template_tree() { $included_files = get_included_files(); $stylesheet_dir = str_replace( ‘\\’, … Read more

Get_template_part() problem with the_content()

The problem is that you are running a loop from secondary query in front-page.php and the loop from main in page-home.php. So, the post data in page-home.php won’t be the data from the WP_Query in front-page.php. Additionally, you are trygin to get full template files as template parts, which is not correct. I mean, front-page.php … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)