Infolinks: In-text advertising for your blog
 

 

Top

Extending Automattic’s Sidebar Widget

May 20, 2007

As you can see, I’ve got a new theme for this website. I’ve tried my best to unclutter the site which is what I thought it was before. Do give me your feedback, if there are ways to make the site look better.

As part of this migration, I wanted to introduce some new features on the site. You’ll see new things on the sidebar like Recent Comments, and Popular Posts.

The blog uses Automattic’s Sidebar Widgets extensively. As part of this process, I realized that many of these plugins like the Popularity Contest plugin for getting the most popular posts is not directly integrated into the widgets. Rather than ditching the plugin, I studied the Sidebar Widget code to figure out the simplest way to integrate it. I’m not sure if there are other ways, but what I’m describing below is in its own way very simple, especially if you are comfortable with PHP.

I’m explaining the integration of the Popularity Contest plugin below.

Open the widgets.php file present under wp-content/plugins/widget/

Add this function:

function popular_links($args) {
echo “<li><h2>Most Popular Posts</h2>”;
echo “<ul>”;
akpc_most_popular();
echo “</ul>”;
echo “</li>”;
}

In the function widgets_init(), add this line towards the end of the function:

register_sidebar_widget(‘PopularLinks’, ‘popular_links’);

Now, go to Presentation -> Sidebar Widgets. You will see a new widget available for you to drag and drop, called PopularLinks. That’s it! It was so simple. :-)

You can use the same logic to add just about any widget to Automattic’s Sidebar Widget.

Popularity: 17% [?]



Comments



One Response to “Extending Automattic’s Sidebar Widget”

  1. MyAvatars 0.2 sterndal on June 10th, 2009 11:23 am

    hi, nice new theme! clean and refreshing :)

Got something to say?





Bottom