ThemeShaper Forums » Thematic

[closed]

is_page_template action hook affecting other pages

(3 posts)
  • Started 13 years ago by wlanni
  • Latest reply from wlanni
  • This topic is resolved
  1. wlanni
    Member

    Hello,

    I'm replacing thematic_sidebar() on a few template pages with a wp_nav_menu. I found the code here Chris wrote to use is_page_template to zero in on specific page templates. However, the action hook is affecting the entire site, and I'm losing my sidebar in my blog pages as well. GRRRR!

    Here's my functions:

    // Register the new menus
    function register_my_menus() {
    	register_nav_menus(
    		array(
    			'primary-menu' => __( 'Primary Menu' ),
    			'products-menu' => __( 'Products Menu' ),
    			'about-menu' => __( 'About Us Menu' ),
    		)
    	);
    }
    add_action( 'init', 'register_my_menus' );
    
    function products_menu_sidebar() {
    	if (is_page_template('products.php')) {
    		wp_nav_menu( array(
    				'theme_location' => 'products-menu',
    				'container_id'=>'products-menu',
    				'container_class' => 'left-menu-container',
                    'menu_class' => 'left-menu',
                    'depth' =>	'0',
                    ) );
    	} else {
    	//nada
    	}
    }
    add_action('thematic_sidebar', 'products_menu_sidebar');

    So the nav menu is showing up on the products.php templated pages. However, on other pages that are using the Blog template, my sidebar is missing.

    What the heck am I doing wrong here?!

    Posted 13 years ago #
  2. wlanni
    Member

    On a sidenote, I wound up hooking into thematic_belowcontainer, as this wound up working better. However, I'd still love to know wtf I was doing wrong above.

    Posted 13 years ago #
  3. wlanni
    Member

    Ah. I figured it out:

    replaced products_menu_sidebar with:

    function remove_sidebar_templates() {
    	global $post;
    	if ( is_page_template('products.php' ) )  {
    		wp_nav_menu( array(
    			'theme_location' => 'products-menu',
    			'container_id'=>'products-menu',
    			'container_class' => 'left-menu-container',
                'menu_class' => 'left-menu',
                'depth' =>	'0',
            ) );
    	} else if ( is_page_template('about.php') ) {
    		 wp_nav_menu( array(
    				'theme_location' => 'about-menu',
    				'container_id'=>'about-menu',
    				'container_class' => 'left-menu-container',
    				'menu_class' => 'left-menu',
    				'depth' =>	'0',
    			) );
    	}else {
    		// we are not .. we leave the switch on
    		return TRUE;
    	}
    }
    add_filter('thematic_sidebar', 'remove_sidebar_templates');

    I still like the nav menus in the thematic_belowcontainer better for styling purposes, but hope this helps anyone looking for this!!

    Posted 13 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.