Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

How to display different sidebar on some pages in wordpress ?

diffrent sidebar in each page

     
12:08 pm on Nov 17, 2014 (gmt 0)

New User from IN 

joined:Nov 4, 2014
posts:15
votes: 0


In my website there has left sidebar ..which shown in every pages i want diffrent sidebar in some pages.

in sidebar.php :

<div id="sidebar">
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
</div>

And functions.php :


if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="left-box"><div class="col-md-12 col-sm-12">',
'after_widget' => '</div><div class="clearfix"></div></div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
12:20 pm on Nov 17, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


Welcome to WebmasterWorld Techbuddy

You just need to use an if/then/else statement and get_post(). [codex.wordpress.org...]

You can locate the id of the pages within the admin area. Go to either Pages or Posts and as you mouse over the edit link you'll see the id in the lower left hand corner of your screen (I think all browsers will display it there).
2:05 pm on Nov 18, 2014 (gmt 0)

New User from IN 

joined:Nov 4, 2014
posts:15
votes: 0


Thanks Lorax..but i have one bolg page where sidebar is diffrent from my homepage.how i can add same designed sidebar with diffrent name.Could changes on right sidebar.php or changes from widget area. ?
7:23 am on Jan 29, 2015 (gmt 0)

New User

5+ Year Member

joined:May 26, 2014
posts: 14
votes: 0


Add addition sidebar inside the function widgets_init() in theme function file

register_sidebar( array(

'name' => __( 'Second Front Page Widget Area', 'themname' ),// change the name for sidebar

'id' => 'sidebar-3',

'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'themename' ),

'before_widget' => '<aside id="%1$s" class="widget %2$s">',

'after_widget' => '</aside>',

'before_title' => '<h3 class="widget-title">',

'after_title' => '</h3>',

) );

then use it with condition on the page

<?php dynamic_sidebar( 'footer-sidebar' ); ?>

its just an example
1:01 pm on Jan 29, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


in theme function file


Please, for your own sake, use a child theme to make these modifications or you'll lose them the next time you update WordPress.