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

         

TechBuddy

12:08 pm on Nov 17, 2014 (gmt 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>',
));

lorax

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

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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).

TechBuddy

2:05 pm on Nov 18, 2014 (gmt 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. ?

webtechnocrazy

7:23 am on Jan 29, 2015 (gmt 0)

10+ Year Member



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

lorax

1:01 pm on Jan 29, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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.