Split Sidebar into Two Divisions

I decided to split sidebar into two divisions. So that I can use the primary sidebar as widgets and secondary sidebar as customize lists. Here is the original sidebar.php.

7
8
9
10
11
12
13
  1. <!-- begin sidebar -->
  2. <div id="sidebar">
  3. <ul>
  4. <!-- sidebar lists -->
  5. </ul>
  6. </div><!-- #sidebar -->
  7. <!-- end sidebar -->

The new sidebar.php will look like this. We remove the sidebar id and replace with primary-side and secondary-side ids. Both elements will have sidebar class.

7
8
9
10
11
12
13
14
15
16
17
18
  1. <!-- begin sidebar -->
  2. <div id="primary-side" class="sidebar">
  3. <ul>
  4. <!-- primary lists -->
  5. </ul>
  6. </div><!-- #primary-side .sidebar -->
  7. <div id="secondary-side" class="sidebar">
  8. <ul>
  9. <!-- secondary lists -->
  10. </ul>
  11. </div><!-- #secondary-side .sidebar -->
  12. <!-- end sidebar -->

In order to activate the widget sidebar, we need to register both primary and secondary sidebar in theme functions file, functions.php, as below.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  1. if ( function_exists('register_sidebar') )
  2. {
  3. // Primary Sidebar
  4. register_sidebar(array(
  5. 'name' => 'Primary Sidebar',
  6. 'id' => 'primary-sidebar',
  7. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  8. 'after_widget' => '</li>',
  9. 'before_title' => '',
  10. 'after_title' => '',
  11. ));
  12.  
  13. // Secondary Sidebar
  14. register_sidebar(array(
  15. 'name' => 'Secondary Sidebar',
  16. 'id' => 'secondary-sidebar',
  17. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  18. 'after_widget' => '</li>',
  19. 'before_title' => '',
  20. 'after_title' => '',
  21. ));
  22. }

Lastly, we need to change the WordPress theme layout, layout.css. Both sidebar elements are right floated. Secondary-side element is cleared to right. So that it can drop below right floated primary-side element.

30
31
32
33
34
35
36
37
38
39
  1. div.sidebar {
  2. float: right;
  3. width: 210px;
  4. margin-left: -250px;
  5. padding: 20px;
  6. }
  7.  
  8. div#secondary-side {
  9. clear: right;
  10. }

Related Posts

No Comments

No comments yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">