Hi everyone,
I’m pretty new to WordPress 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>',
)
);
}