Community Forums › Forums › Archived Forums › Design Tips and Tricks › Hooking up Page and Category specific widget area
- This topic has 6 replies, 4 voices, and was last updated 8 years, 10 months ago by nomis.
-
AuthorPosts
-
May 20, 2015 at 11:51 am #152934nomisMember
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 #152971Brad DaltonParticipantMay 20, 2015 at 4:02 pm #152975nomisMemberThanks 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,
siMay 20, 2015 at 4:34 pm #152981Brad DaltonParticipantMay 20, 2015 at 11:04 pm #153054coralseaitMemberMay 20, 2015 at 11:21 pm #153059Genesis DeveloperMemberUsing this Pro plugin you can easily achieve this. You do not need to write any extra code.
May 21, 2015 at 12:45 pm #153128nomisMemberThanks 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>', ) ); }
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.