Posted By

kstetson on 06/03/09


Tagged

wordpress dynamic multiple sidebars


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

stevetronix
joelhaus
lexpresso


Multiple Dynamic Sidebars in Wordpress


 / Published in: PHP
 

To arrange multiple dynamic sidebars in wordpress, add the following code snippet into functions.php. The sidebar should then appear in the dropdown menu in wordpress under the widgets section. Next, go into your sidebar.php file & edit the dynamic sidebar tag by setting conditionals for when certain sidebars can be used in the sidebar.php file.

  1. // use in functions.php:
  2.  
  3. <?php
  4. // Multiple Sidebars
  5. if ( function_exists('register_sidebar') ) {
  6. register_sidebar(array(
  7. 'name'=>'Page',
  8. 'before_widget' => '<li>',
  9. 'after_widget' => '</li>',
  10. 'before_title' => '<h2>',
  11. 'after_title' => '</h2>',
  12. ));
  13. register_sidebar(array(
  14. 'name'=>'Blog',
  15. 'before_widget' => '<li>',
  16. 'after_widget' => '</li>',
  17. 'before_title' => '<h2>',
  18. 'after_title' => '</h2>',
  19. ));
  20. register_sidebar(array(
  21. 'name'=>'Single',
  22. 'before_widget' => '<li>',
  23. 'after_widget' => '</li>',
  24. 'before_title' => '<h2>',
  25. 'after_title' => '</h2>',
  26. ));
  27. }
  28.  
  29.  
  30. // use in sidebar.php:
  31.  
  32. <?php // Load Dynamic Sidebars
  33. if(!function_exists('dynamic_sidebar')) {
  34. showDefault();
  35. } else {
  36. if(is_front_page()) {
  37. if(!dynamic_sidebar('homepage')) {
  38. showDefault();
  39. }
  40. } else {
  41. if(!dynamic_sidebar('global')) {
  42. showDefault();
  43. }
  44. }
  45. }
  46. ?>

Report this snippet  

You need to login to post a comment.