0

i use the following code in my functions.php. I want to exclude all pages which use the single.php template.

function cat_menu() {

 if (!is_page_template('single.php')) {


$cur_cat = get_query_var('cat');

 $new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat .'&depth=1&title_li=&&show_count=0&hide_empty=1');
            echo '<ul>' . $new_cats . '</ul>';
}}
  add_action ( 'genesis_after_header', 'cat_menu' ); 

But i see the result aslo on pages which use the single.php.

Can somebody help me with this?

0

is_page_template() checks against post type templates specified by the theme using

/**
 * Template Name: My Template
 */

at the top of the template file. Not any arbitrary template file. For this, you might wanna check out the answers over at Get name of the current template file. You could grab the code from the accepted answer there (get_current_template()) to do something when single.php === get_current_template().

0

You must to use the next function:

is_singular()

Is singular checks if current page is single.php.

Function reference

  • is_singular() doesn't 100% guarantee that single.php was loaded, as other templates in the hierarchy might be loaded before it. – swissspidy Jan 25 '17 at 13:05
-1

get_page_template_slug() - Returns only the page template

 global $post;    
    $template = get_page_template_slug($post->ID);         
    if ($template == 'page-template.php') {....}

Probably worth checking out easier

if(is_single()){....}
  • This is the same problem as with is_page_template(). get_page_template_slug() only checks for custom post templates (the ones with the /* Template Name: ... */ headers). Also, is_single() doesn't 100% guarantee that single.php was loaded, as other templates in the hierarchy might be loaded before it. – swissspidy Jan 25 '17 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.