Conditional Action Hook Question

Homepage Community Forums General Conditional Action Hook Question

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #15861
    nomis
    Customer

      Hi again,

      I’m working with the Epik theme which uses Action Hooks to add and remove widget areas. My site divides posts into two main categories. The two blogs are completely separate from each other and are accessed by separate main menu items. Clicking on “Blog” takes you to a normal blog, and clicking on “Tutorials” takes you to a portfolio template page which leads through to completely separate tutorial posts.

      So far I have registered two widget areas to the ‘genesis_after_header’ hook. One widget appears on the Blog Page, and the other appears on the Tutorials Page. They both contain custom menus. This means that when you’re in the Blog, you can filter the blog categories, and when you’re in Tutorial you can filter the tutorial categories. The Tutorial Submenu filters by removing categories from the portfolio page. This is the code that I’m using, and it works just fine:

      // **************************** BLOG SUBMENU WIDGET ****************************
      //* rise - Register blog-submenu widget area
      genesis_register_sidebar( array(
      	'id'            => 'blog-submenu',
      	'name'          => __( 'Blog Submenu', 'epik' ),
      	'description'   => __( 'Place submenu for Blog Page here', 'epik' ),
      ) );
      
      //* rise - Hook blog-submenu widget area after header
      add_action( 'genesis_after_header', 'add_blog_submenu' );
      function add_blog_submenu() {
      	if  (is_singular(post) && is_category('Blog') || is_category('Blog_Web') || is_category('Blog_Photos') || is_category('Blog_General') || is_page('Blog'))
      		genesis_widget_area ('blog-submenu', array (
      		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
      		'after'  => '</div></div>',
      		)
      	);
      }
      
      // ***************************** TUTS SUBMENU WIDGET ***************************
      //* rise - Register tuts-submenu widget area
      genesis_register_sidebar( array(
      	'id'            => 'tuts-submenu',
      	'name'          => __( 'Tuts Submenu', 'epik' ),
      	'description'   => __( 'Place submenu for Tuts Page here', 'epik' ),
      ) );
      
      //* rise - Hook tuts-submenu widget area after header
      add_action( 'genesis_after_header', 'add_tuts_submenu' );
      function add_tuts_submenu() {
      	if (is_page('Illustrator Tutorials') || is_page('Sublime Text Tutorials') ||  is_page('Photoshop Tutorials') || is_page('Tutorials') || is_category('Tuts_PS') || is_category('Tuts_Ill') || is_category('Tuts_ST'))
      		genesis_widget_area ('tuts-submenu', array (
      		'before' => '<div class="wrap"><div class="tuts-submenu widget-area">',
      		'after'  => '</div></div>',
      		)
      	);
      }
      

      However, the filter menus (Submenus) were not showing up on single posts. So I added (is_singular(‘post’) to the Blog Submenu code:

      //* rise - Hook blog-submenu widget area after header
      add_action( 'genesis_after_header', 'add_blog_submenu' );
      function add_blog_submenu() {
      	if  (is_singular(post) || is_category('blog_web') || is_category('blog_photos') || is_category('blog_general') || is_page('blog'))
      		genesis_widget_area ('blog-submenu', array (
      		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
      		'after'  => '</div></div>',
      		)
      	);
      }
      

      This worked fine, but the blog-submenu was now also showing on the Tutorial single posts. So I added (is_singular(post) && is_category(‘blog’). My thought was that this would only add the blog-submenu to single posts that also had the Blog category attached to them.

      //* rise - Hook blog-submenu widget area after header
      add_action( 'genesis_after_header', 'add_blog_submenu' );
      function add_blog_submenu() {
      	if  (is_singular(post) && is_category('blog') || is_category('blog_web') || is_category('blog_photos') || is_category('blog_general') || is_page('blog'))
      		genesis_widget_area ('blog-submenu', array (
      		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
      		'after'  => '</div></div>',
      		)
      	);
      }
      

      But this made the blog-submenu disappear from ALL single posts. So I added this (is_singular(post) && !is_category(‘Tutorials’). My thought was that this would only add the blog-submenu to single posts that did NOT have the Tutorials category attached to them.

      //* rise - Hook blog-submenu widget area after header
      add_action( 'genesis_after_header', 'add_blog_submenu' );
      function add_blog_submenu() {
      	if  (is_singular(post) && !is_category('Tutorials') || is_category('Blog_Web') || is_category('Blog_Photos') || is_category('Blog_General') || is_page('Blog'))
      		genesis_widget_area ('blog-submenu', array (
      		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
      		'after'  => '</div></div>',
      		)
      	);
      }
      

      This did not remove the blog-submenu from single posts that had the Tutorials category attached.

      So basically, I want to add the blog-submenu widget to single posts that have the Blog category, but not the Tutorials category. Can anyone help?

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.