How to add a widget to the sidebar
Posted in: WordPress
There are basically two ways to add widgets to the sidebar. The easy one for people who use a widget-ready theme, and then there’s the way for people who are either using a non-widget-ready theme or are weird German guys with too much time on their hands, who prefer to mess with the code. Uhm, yeah, that would be me.
The easy way
Go to your admin panel and click on presentation. Under “widgets” you see your sidebar(s). Don’t worry, that’s just the widgets. The non-witgetized parts of the sidebar are not shown. You didn’t lose them.
Drag a “Text 1″ widget into your sidebar.
Click the configure button on the right.
Paste the code you copied from the widget provider (i. e. BlogCatalog) into the big text field.
Close it, click “Save Changes” and you should be set.
The harder way
Open your sidebar.php in a text editor. I prefer to have the widget above the meta section of the sidebar, so I look for it in the code. Ah, there it is.
<li><h2>Recent Entries</h2>
<ul>
<?php query_posts(’showposts=10′); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title() ?></a></li>
<?php endwhile; endif; ?>
</ul>
</li><li><h2>Meta</h2>
<ul>
…
It will look different in your theme. Just make sure you found the meta part. Before you edit anything, you should make sure that you have a backup copy of the file. Now I will paste the code from the widget provider into the theme, which results in this:
<li><h2>Recent Entries</h2>
<ul>
<?php query_posts(’showposts=10′); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href=”<?php the_permalink() ?>”><?php the_title() ?></a></li>
<?php endwhile; endif; ?>
</ul>
</li><ul>
<li><script type=”text/javascript” src=”http://www.blogcatalog.com/w/recent.php?id=XXXXXX”/script></li>
</ul><li><h2>Meta</h2>
<ul>
…
As you can see, I also gave it ul and li tags, to match the rest of the sidebar. Save the file, upload it to your ftp, thus replacing your old sidebar.php. You should be able to see your shiny new widget now.
I hope this was of help to you. If it was (even if not), drop me line. I’m always interested in feedback.
Return to: How to add a widget to the sidebar
Social Web