• Howdy!

    I have three widgets that I want to place in a sidebar and each one should contain recent posts from three different categories.

    • Industry news
    • Sales news
    • Personnell news

    These three are post categories and each should go in their own widget.

    I have tried to look here and found a tip that said to insert the below in functions:

    add_filter('widget_posts_args','modify_widget');
    
    function modify_widget() {
        $r = array( 'cat' => 'industry' );
        return $r;

    How do I specify the categories to each filter?

    Thanks a lot in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi

    Why don’t you use the Recent Posts Widget Extended plugin.

    much easier and it means you have a lot more flexibility.

    Kevin

    Hey Robert!

    I built out a site with a similar need a little while ago – try out the “Latest Custom Post Type Updates” plugin – it’s a free plugin that should do exactly what you’re look for. You can create an instance of the widget for each of your three items, the configure it for each one. You’ll want to edit the “Advanced Settings” for each of the widgets, and select “Filter By Taxonomy checkbox” Then select Filter By “Categories,” then select your respective category.

    Let me know how that goes!

    bryan

    Thread Starter r0bert

    (@r0bert)

    Thanks a lot for your answer!

    That seems exactly what I’d need. However, I forgot to say that I can’t use any plugins for this project. I need to write all the code…

    Thanks though!

    In which case rather if you can run php in your widgets then it would probably be easier to run a custom loop in a text box.

    then each text box in the widget you can run the loop for each category.

    Robert – Gotta say that’s pretty strange – You want to use plugins for these types of things to make it easier for you ( or the person your building the site for) to update it later on. Any code you write is a potential liability that could cause problems later on if not maintained. That said, kevin provides a valid option.

    http://www.emanueleferonato.com/2011/04/11/executing-php-inside-a-wordpress-widget-without-any-plugin/

    Not to belabor this point – but this is really not the best way to do it – php in the widgets opens up an attack vector for bad guys, and opens up the potential to crash your site if there’s a php error in the widget code. It’s also code that’s not in version control, and will be hard to keep track as the site develops, etc, etc.

    Good luck!

    Thread Starter r0bert

    (@r0bert)

    purcebr – I couldn’t agree more. It’s backwards in a way and I’m sure there are plenty of plugins that would be safe & effective. In a future project I would not go about this the same way.

    Thanks for your input purcebr & Kevin!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add recent post from one category in a widget’ is closed to new replies.