get_template_part for specific page

This is just a supplement to the other answer. I am trying to load fd-blog.php if it is the ‘Blog’ page, otherwise load the fd-default.php To actually load the template file, you should remove the dash (-): get_template_part( ‘inc/fd’, ‘blog’ ); // loads inc/fd-blog.php get_template_part( ‘inc/fd’, ‘default’ ); // loads inc/fd-default.php So just inc/fd, and … Read more

How do I display an image before the first post of the loop when I’m using get_template_part?

The variable $count is accessible in the scope of the current function only. So whatever happens inside get_template_part() cannot know that variable. You could use a global variable, which is accessible everywhere as $GLOBALS[‘count’]. But then you risk collisions with plugins and maybe other code. I recommend a helper function for the functions.php: /** * … Read more

Change the file path on get_template_part via plugin

Well, I handle this issue by adding some code above get_template_part() function in theme as: //Theme /* If any filter set */ if(has_filter(‘ppr_one_search_item_view’){ $themePartSlug = apply_filters(‘ppr_one_search_item_view’); } else{ $themePartSlug = ‘templates/search/place’; } get_template_part($themePartSlug); in my plugin: /* Plugin Code */ function get_template_part_place(){ // Template file from plugin Directory load_template(PPR1_PLUGIN_PATH.’templates/search_places.php’); } add_filter( ‘ppr_one_search_item_view’, ‘get_template_part_place’); /* plugin … Read more

Detect if current page is front page within custom query

Marius, I have been in this situation before as well. Haven’t found a good solution though. Answer provided by Laxmana won’t work as the $isFrontPageOrSearch wont be accessible inside the template-part file. Although using the approach provided by Laxmana, you could be using PHP include(locate_template(‘your-template-name.php’));, instead of using get_template_part function. Then the variable would be … Read more

get_template_part based upon post’s category

It looks like the single quotes are giving you problems. Replace: get_template_part( ‘templates’, ‘$childcat->slug’ ); with: get_template_part( ‘templates’, $childcat->slug ); Note that double quoted strings in PHP can parse variables, not single quotes. Also check out the curly syntax in the PHP docs in the variable parsing section.