• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Hooking up Page and Category specific widget area

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Hooking up Page and Category specific widget area

This topic is: not resolved
  • This topic has 6 replies, 4 voices, and was last updated 11 years, 1 month ago by nomis.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • May 20, 2015 at 11:51 am #152934
    nomis
    Member

    Hi everyone,
    I’m pretty new to WordPress, StudioPress and PHP so I hope someone can help me. My site has two blog pages. One is a standard blog, and the other is for tutorials. I’ve written the PHP below to add a widget area to the standard blog page, and also to its three category pages. I’ve added a custom menu to this area so that the viewer can switch between blog categories and also go back to the standard/all category page.

    Here’s the thing - It works just fine. But the PHP just doesn’t look quite right to me. Shouldn’t there be an “else” statement at the end rather than an “elseif” ? When I add it, everything breaks. And do I really have to repeat all this code four times? Couldn’t I just group the page/category numbers in one block?

    Any help cleaning up this very amateur code would be greatly appreciated.

    //*  Register blog-submenu widget area
    genesis_register_sidebar( array(
    	'id'            => 'blog-submenu',
    	'name'          => __( 'Blog Submenu', 'epik' ),
    	'description'   => __( 'Place submenu for Blog Page here', 'epik' ),
    ) );
    //* Hook blog-sub-menu widget area after header
    add_action( 'genesis_after_header', 'add_blog_submenu' );
    function add_blog_submenu() {
    	if ( is_page('59') )
    		genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    	elseif ( is_category('11') )
    	genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    	elseif ( is_category('12') )
    	genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    	elseif ( is_category('13') )
    	genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }
    May 20, 2015 at 3:42 pm #152971
    Brad Dalton
    Participant

    What breaks?

    There's different ways to code else statements.


    Tutorials for StudioPress Themes.

    May 20, 2015 at 4:02 pm #152975
    nomis
    Member

    Thanks for your reply Brad,
    The code works perfectly as written above, but when I change the final elseif to else, it goes white-screen.

    Bearing in mind that it seems to work as is, is there anything actually wrong with the PHP above - should I change anything?

    Thanks,
    si

    May 20, 2015 at 4:34 pm #152981
    Brad Dalton
    Participant

    Works for me.

    Try these
    http://php.net/manual/en/control-structures.elseif.php
    http://php.net/manual/en/control-structures.else.php


    Tutorials for StudioPress Themes.

    May 20, 2015 at 11:04 pm #153054
    coralseait
    Member

    Another option is a switch statement:

    http://php.net/manual/en/control-structures.switch.php


    Coral Sea IT

    May 20, 2015 at 11:21 pm #153059
    Genesis Developer
    Member

    Using this Pro plugin you can easily achieve this. You do not need to write any extra code.


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    May 21, 2015 at 12:45 pm #153128
    nomis
    Member

    Thanks everyone for you help and advice. Eventually I narrowed it down to the code below, which is much more compact but still seems to work fine.

    //* 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_page('59') || is_category('11') ||  is_category('12') || is_category('13'))
    		genesis_widget_area ('blog-submenu', array (
    		'before' => '<div class="wrap"><div class="blog-submenu widget-area">',
    		'after'  => '</div></div>',
    		)
    	);
    }
  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble