Make money online using Kontera's In-Text Advertising
 

 

Top

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 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.

Rate this:
3.0
Save the page: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • StumbleUpon
  • Digg
  • del.icio.us
  • Technorati
  • Reddit
  • Bumpzee
  • YahooMyWeb
  • BlinkList
  • PlugIM
  • Facebook
  • Furl
  • Live
  • Mixx
  • SphereIt
  • Sphinn
  • Google
  • IndianPad
  • Pownce
  • TailRank
  • TwitThis

Comments



Got something to say?





Bottom