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

Can’t load search results with ajax

The JavaScript should be: <script> jQuery( document ).ready(function ( $ ) { $( “#searchform” ).on( “submit”, function ( ev ) { ev.preventDefault(); $.post( “<?php echo admin_url( ‘admin-ajax.php’ ) ?>”, { action: “wpa56343_search”, search: $( “#s” ).val() }, function ( response ) { $( “body” ).append( response ); } ); }); }); </script> And the AJAX … Read more

Get template part with CPT and Custom Taxonomy conditionals

Your order of your if/else statement is wrong. You would want to have your complex condition (or most important condition) at the top and the simplest (or least important condition) at the bottom. if/else statements work on the basis that the first condition that hits true will be executed. In your example above, if you … Read more