Support » Plugins » Hacks » Recent Posts Widget with Category Exclude

  • Resolved lawless


    I just needed to modify the default WP_Widget_Recent_Posts widget so I could exclude specific Categories. I needed the Exclude fields to be editable in the Admin Widget so if the client adds new Categories they can manage the Widget themselves. This is probably better off as a Plug-in, but I just threw it in my theme’s functions.php for simplicity.

    Here’s the code in case someone can use it, just drop it into your theme’s functions.php file (if I’ve made this needlessly complicated, I’d love to hear it, I could probably do this with a filter, but it would be hard-coded and not editable in the Admin):

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hey Lawless,
    I am looking for the exact same thing… could you repost your code on pastbin and link to it here? Thanks.

    Thread Starter lawless


    Link posted below.

    Thread Starter lawless


    Recent Posts Widget with Category Exclude:

    Just drop that whole thing in your theme’s functions.php file and it will turn the Recent Posts widget into a Recent Posts with Exclude widget.

    WOW – spot on! This was exactly what I needed.

    Thanks lawless:)

    This is fantastic! Thank you.

    Thanks for sharing that link it was just what I was looking for. For those reading that are not sure how to use it here is what I did. I copied the code and pasted it at the very bottom of my functions.php. Then go to your widgets and drag it over *poof* there it is. It took me all of two minutes to get it going. Oh and if you don’t know your CAT id because you used a slug just go to edit categories and click edit on the category you want to exclude and it will show in the URL at the top of your browser.

    Thanks a lot, mate! I was going crazy with lots of plugins to achieve this little task.

    Thread Starter lawless


    Cheers. Funny, every couple months someone stumbles onto this post and the Recent Posts w/ Category Exclude widget.

    I don’t even remember what project I used it in now, and haven’t used it since, but it’s good to see others getting some use out of it.


    Been hunting high and low for this solution. Many thanks. Why can’t WP add this to a version update? So many people seem to want this functionality


Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Recent Posts Widget with Category Exclude’ is closed to new replies.