« First steps
Tag, you got it. »

Making a hole in the sidebar

The next step is fixing the sidebar. As this is a pretty old theme, the sidebar is rather statically set up. It links your pages, categories and links. Nowadays these Widgets are all the rage - and it isn’t hard to set up support for them in an old theme either.

First we’ll make the sidebar accept widgets. The easy, and right, way is to wrap the old sidebar in a condition saying it should be displayed if there is no support for widgets. Do it like this; insert line 2 and 15, making the code look like below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<div id="sidebar">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<h2>Pages</h2>
<ul>
<li><a href="<?php echo get_settings('home'); ?>/">Home</a></li>
<?php wp_list_pages('title_li='); ?>
</ul>
<h2>Categories</h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
</ul>
<ul>
<?php get_links_list(); ?>
</ul>
<?php endif; ?>
</div>

Here we could have made the container around sidebar into an unordered list (ul), but that would mean we’d have to have a look at the css to get things to display correctly. So instead we must do a small fix in functions.php. Instead of using register_sidebars we’ll use register_sidebar (plural vs. singular) with some parameters.

Since the functions.php to register dynamic sidebars in doesn’t exist, we’ll have to create it. Put it in the theme’s folder, and make it contain the following code. Be careful; no space or newlines before or after the lines of code:

1
2
3
4
<?php
if ( function_exists('register_sidebar') )
    register_sidebar(array('before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>'));
?>

The before and after_widget parameters wraps each widget in a div. This wouldn’t be necessary if the dynamic sidebar call was issued from inside an unordered list (ul), as the default values produces list elements (li).

Now the only task left is to go into the widget page (in the blog administration) and add what you want. I suggest Pages, Categories and Links if you want to keep the feel of Simpla, as it were. Keep tuned for more.

Anything you want to add, ask or tell? Feel free. :)

Related Posts:

  • I'd love some feedback on this entry; feel free to write a piece in the comments. Did you find this interesting? Informative? Confusing? Lacking information, references or sense? I'd like to improve, feedback would help me immensely!
« First steps
Tag, you got it. »

Leave a Reply