Julian
Julian

Reputation: 1831

Styling for WordPress sidebar not looking right - dynamic_sidebar()

Custom sidebars has been a breeze so far except with it comes unto the blog 'Category'.

Notice how it looks perfectly here on the 'Page' version - http://70.87.35.71/~life/?page_id=87

but the same sidebar has different elements the category version - http://70.87.35.71/~life/?cat=1

Why does the sidebar look so crappy when under the category section and how do I make it look like the 'Page' version.

My sidebar code is below

<div id="sidebar" class="clearfix">



<?php 

if ( !in_category('1') ) {
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') )
    {}

}
else {
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Blog') )
    {}

}
?> 
</div> <!-- end sidebar -->

Upvotes: 0

Views: 624

Answers (2)

Chris_O
Chris_O

Reputation: 3444

There is no need to check if function_exists. It has existed since WordPress version 2.1.

Your display problem is due the sidebar blog sidebar not being registered properly.

add_action( 'widgets_init', 'add_blog_sidebar' );
function add_blog_sidebar() {

register_sidebar(array(
    'name' => 'Blog Sidebar',
         'id'         =>  'blog',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="widgettitle">',
        'after_title' => '</h3>',
    ));
}

The before widget and before title arguments are needed to allow for styling.

Calling your dynamic sidebar:

if ( is_category('1') dynamic_sidebar( 'blog' );
    else dynamic_sidebar( 'sidebar');

To learn everything there is to know about sidebars check out Justin Tadlock's sidebar tutorial.

Upvotes: 1

Zhianc
Zhianc

Reputation: 1451

Try changing it to:

<?php     
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Blog') )
    {}
?>

remove the if else statement.

Upvotes: 0

Related Questions