Extending Automattic’s Sidebar Widget
May 20, 2007
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
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.
| 3.0 |























Anuj Seth · Filed Under 






Comments
Got something to say?