WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Recent Posts Widget with Category Exclude (12 posts)

  1. lawless
    Member
    Posted 1 year ago #

    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]

  2. Baden
    Member
    Posted 1 year ago #

    Hey Lawless,
    I am looking for the exact same thing... could you repost your code on pastbin and link to it here? Thanks.

  3. lawless
    Member
    Posted 1 year ago #

    Link posted below.

  4. lawless
    Member
    Posted 1 year ago #

    Recent Posts Widget with Category Exclude:
    http://pastebin.com/jxDnqPqR

    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.

  5. KylieZona
    Member
    Posted 1 year ago #

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

    Thanks lawless:)

  6. simojoki
    Member
    Posted 1 year ago #

    This is fantastic! Thank you.

  7. DailyTrudge
    Member
    Posted 1 year ago #

    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.

  8. Adrian Verstuyft
    Member
    Posted 1 year ago #

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

  9. lawless
    Member
    Posted 1 year ago #

    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.

  10. David Rogers
    Member
    Posted 1 year ago #

    Outstanding!

  11. TinPianoMan
    Member
    Posted 1 year ago #

    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

  12. kathycac
    Member
    Posted 11 months ago #

    THANK YOU!

Topic Closed

This topic has been closed to new replies.

About this Topic