Skip to main content

Ivan Teoh

Something personal yet public

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.

55-sidebar.php (Source)

<?php
/**
 * @package WordPress
 * @subpackage Your_Theme
 */
?>
<!-- begin sidebar -->
<ul>
    <?php   /* Widgetized sidebar, if you have the plugin installed. */
        if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    <li>
        <label for="s"><?php _e('Search'); ?></label>
        <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
            <input type="text" name="s" id="s" size="15" /><br />
            <input type="submit" value="<?php _e('Search'); ?>" />
        </form>
    </li>

    <?php wp_list_pages('title_li=' . __('Pages')); ?>

    <li><?php _e('Archives'); ?>
        <ul>
            <?php wp_get_archives('type=monthly'); ?>
        </ul>
    </li>

    <?php wp_list_categories('title_li=' . __('Categories')); ?>

    <?php wp_list_bookmarks('title_after=&title_before='); ?>

    <li><?php _e('Meta'); ?>
        <ul>
            <?php wp_register(); ?>
            <li><?php wp_loginout(); ?></li>
            <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>
            <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>
            <?php wp_meta(); ?>
        </ul>
    </li>
    <?php endif; ?>
</ul>
<!-- end sidebar -->

Comments

Comments powered by Disqus