Widgetized my theme

In preparation of installing WordPress 2.5 I finally widgetized my theme. I’m using an old 2.0 version of FastTrack. Widgets have been around for a long time so as I play with 2.5 I figured I’d come up to speed with a 2.0 feature.

I had a bunch of nested if..thens so that the home page would show one sidebar and single posts and pages would show another. I had cleaned up the theme so I now had separated the two sidebars in the file.

In my theme’s function.php I added the following lines:

if ( function_exists(’register_sidebar’) )
register_sidebars(2,array(
‘before_widget’ => ”,
‘after_widget’ => ”,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’,
));

This let me define 2 sidebars, one for the home page and one for not the home page.

In my sidebar.php I placed

php code for the is_home() sidebar

<?php endif; ?>

<?php } else { ?>

<?php if ( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar(2) ) : ?>

php code for the all other pages sidebar

<?php endif; ?>

<?php }?>

This let me have a default for each sidebar. That’s where I ran into a snag. I want to re-use the same widgets in both sidebars. The widgets won’t let me use them twice. I wanted to use the meta widget on the home page as well as on the single posts.

If I want I can define additional duplicate widgets but that’s a pain. I’m playing with the idea of defining a third dynamic sidebar and display that on the bottom of each sidebar.

I’ll keep playing with it to find a solution I like.

2 Replies to “Widgetized my theme”

  1. This is a useful post. I am trying the same thing with my site and ran into the exact same snag you describe! I’m glad I’m not the only one who has discovered this problem.
    I was waiting for 2.5 with such hope that they would have a fix for this issue, but alas…
    What solution did you eventually find? I’d be very interested to get a little update to your post.

  2. Ryan,

    I’m still playing around with it but I think the only solution is to define additional widgets in function.php.

    What I want to do is create widgets that can be re-used like the text or RSS widget.

    Most likely I’ll have an update by the end of this week.

    Thanks,

    Jan Dembowski

Comments are closed.