Philip Kirkbride
Philip Kirkbride

Reputation: 22859

Edit Wordpress recent posts widget to exclusive categories

I want to edit the recent posts widget to only include certain categories.

  1. Is the location of this widgets code standardized across themes? If so which file is it in?

  2. What edit do I have to make to achieve this?

Upvotes: 0

Views: 4744

Answers (2)

Stephanie Gredell
Stephanie Gredell

Reputation: 168

You can use a filter to change the widget. Here's an example on this. You would just have to change 6 to the category ID you want to use. This would go in your functions.php file.

add_filter('widget_posts_args','modify_widget');

function modify_widget() {
    $r = array( 'cat' => '6' );
    return $r;
}

Upvotes: 2

markratledge
markratledge

Reputation: 17561

1) The Recent Posts Widget is Wordpress core and is not in a theme (unless the them specifically includes a different recent posts widget).

2) Don't edit core WP files; it's bad practice. Read https://wordpress.stackexchange.com/questions/1564/modifying-wordpress-core-files

Best practice: use http://wordpress.org/plugins/custom-recent-posts-widget/ that lets you exclude categories, or another widget from http://wordpress.org/plugins/

Upvotes: 1

Related Questions