WordPress Theme Development 5 – Sidebar

In the main index template file, index.php, I added sidebar include tag, get_sidebar();. This tag will include the file sidebar.php. Now, I will talk about what information will be included in this file.
Your sidebar needs to support dynamic widget sidebar as well as old style sidebar. Hence, <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?> is needed. Next, it will be the search form. I include text input and submit input in the form. I also like to display a list of WordPress pages as links, a monthly archive links list, a list of categories as links and a list of bookmarks as links. Since all the links title does not have any html tag, I will remove both the default before text, <h2>, and default after text, </h2>, by adding empty string for title_after and title_before arguments in bookmark template tag. For meta tag list, I added wp_register(); for displaying either the “Register” link to users that are not logged in or the “Site Admin” link if a user is logged in. Adding some WordPress build-in feeds for allowing your friends to subscribe your blog, which is what I doing too. Lastly, wp_meta(); is added for allowing other WordPress plugin to insert content into this file. An example of this file is stated as following.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage Your_Theme
  5. */
  6. ?>
  7. <!-- begin sidebar -->
  8. <ul>
  9. <?php /* Widgetized sidebar, if you have the plugin installed. */
  10. if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
  11.  
  12. <li>
  13. <label for="s"><?php _e('Search'); ?></label>
  14. <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
  15. <input type="text" name="s" id="s" size="15" /><br />
  16. <input type="submit" value="<?php _e('Search'); ?>" />
  17. </form>
  18. </li>
  19.  
  20. <?php wp_list_pages('title_li=' . __('Pages')); ?>
  21.  
  22. <li><?php _e('Archives'); ?>
  23. <ul>
  24. <?php wp_get_archives('type=monthly'); ?>
  25. </ul>
  26. </li>
  27.  
  28. <?php wp_list_categories('title_li=' . __('Categories')); ?>
  29.  
  30. <?php wp_list_bookmarks('title_after=&title_before='); ?>
  31.  
  32. <li><?php _e('Meta'); ?>
  33. <ul>
  34. <?php wp_register(); ?>
  35. <li><?php wp_loginout(); ?></li>
  36. <li><a title="<?php _e('Syndicate this blog using RSS'); ?>" href="<?php bloginfo('rss2_url'); ?>"><?php _e('Blog <abbr title="Really Simple Syndication">RSS</abbr> Feed'); ?></a></li>
  37. <li><a title="<?php _e('The latest comments to all posts in RSS'); ?>" href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr> Feed'); ?></a></li>
  38. <?php wp_meta(); ?>
  39. </ul>
  40. </li>
  41. <?php endif; ?>
  42. </ul>
  43. <!-- end sidebar -->

Related Posts

References

3 Comments

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="">