Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14322 closed enhancement (worksforme)

Easier configuration/modification of Recent Posts widget

Reported by: zooney's profile Zooney Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.0
Component: Widgets Keywords:
Focuses: Cc:

Description

As far as I can tell from scrounging through the documentation, there are no filters/actions/etc. for modifying the output of the Recent Posts Widget.

It seems silly that I should have to recreate this widget simply to change how it outputs the recent posts (for instance simply to add a "by [author]" after the link to the post).

Since this widget is so commonly used in Wordpress, why not give themers and coders ways to get in and tweak it a bit instead of essentially having to rebuild it again from the ground up?

This is just a thought, and thanks in advance for taking the time to consider it.

Change History (4)

#1 @scribu
14 years ago

  • Severity changed from normal to minor
  • Type changed from feature request to enhancement

You don't have to rebuild the entire widget, just the method that does the outputing:

Class My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {

  function widget($args, $instance) {
    // custom code here
  }
}

#2 @Zooney
14 years ago

Ah-ha! So you can extend that class. I was digging through the Codex and forums and Googling like mad and I couldn't figure out what the class name of that widget was.

Thanks!

Although I still think a filter might make this a bit easier on themers. If this widget is part of core, it just seems like it being able to customize it a bit more easily would be great. It's such a commonly used thing.

#3 @scribu
14 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

All widget classes are found in wp-includes/default-widgets.php

Closing as worksforme. Feel free to reopen with a working patch.

#4 @scribu
14 years ago

I should also mention that you need to register your new class:

function my_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('My_Recent_Posts_Widget');
}
add_action('widgets_init', 'my_widget_registration');
Note: See TracTickets for help on using tickets.