Viewing 15 replies - 1 through 15 (of 21 total)
  • Plugin Author janw.oostendorp

    (@janwoostendorp)

    You can do it in your functions.php like this:

    add_action('template_redirect', function () {
      if ( has_category('category-slug') ) {
        add_filter('dfi_thumbnail_id', function () { return 12; //media id } );
      } else if( has_category('diffrent-category-slug') ) {
        add_filter('dfi_thumbnail_id', function () { return 200; //media id } );
      }
    });

    You probably are wondering why you can’t set it on the category (edit) page. It’s a lot more complicated, a post can have multiple categories, how would I chose (for you) which category I should pick? And should a parent overrule a child or the other way around?

    There will have to be some logic behind it. And I’m sure my choices won’t make sense to everybody. The code isn’t that hard.

    I’m not saying I’ll never implement it but I don’t know when and how. Probably I’ll do post-types first.

    Thread Starter JeffreySummers

    (@jeffreysummers)

    Appreciate the response. I see what you’re saying about multiple categories and I would simply choose the main category as you suggest. I know just enough code to get me into trouble so I’ll see if I can find someone to do that part of it before I mess it up.

    Thanks again. Appreciate the follow-up very much.

    Jeffrey

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    Let me know if you can’t figure it out.

    Thread Starter JeffreySummers

    (@jeffreysummers)

    I can’t figure it out. = )

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    Straight forward answer πŸ™‚

    1) Did you paste my code above in functions.php of your theme?
    2) In my code there is a 'category-slug' change that to the slug of your categories, you can find that on the category pages.
    3) This way add all categories you need, in the example there are two to add more duplicate the } else if( line and the one below that.
    4) in the return 12; //media id replace the number with the media id. You can find the media id on a media page, look at the url It will be something like: wp-admin/post.php?post=694&action=edit use that number.

    Give it a try and let me know πŸ˜‰

    Thread Starter JeffreySummers

    (@jeffreysummers)

    Have 26 categories to build – will try. Where in the function.php does it go? Matter?

    Thread Starter JeffreySummers

    (@jeffreysummers)

    This is what I got…

    add_action(‘template_redirect’, function () {
    if ( has_category(’10-things’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17158; //media id } );
    } else if( has_category(‘culinary’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17155; //media id } );
    } else if( has_category(‘foh’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17149; //media id } );
    } else if( has_category(‘holiday-posts’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17159; //media id } );
    } else if( has_category(‘hotel-notes’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17157; //media id } );
    } else if( has_category(‘travel-tuesday’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17147; //media id } );
    } else if( has_category(‘how-we-see-it’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17107; //media id } );
    } else if( has_category(‘coach’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16137; //media id } );
    } else if( has_category(‘consult’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17160; //media id } );
    } else if( has_category(‘podcasts’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17148; //media id } );
    } else if( has_category(‘pub-speak-facilitate’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16785; //media id } );
    } else if( has_category(‘qfo’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16789; //media id } );
    } else if( has_category(‘they-just-dont-get-it’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17153; //media id } );
    } else if( has_category(‘marketing-branding’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17151; //media id } );
    } else if( has_category(‘groupon’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17146; //media id } );
    } else if( has_category(‘guest-experience’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17143; //media id } );
    } else if( has_category(‘social-business’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17142; //media id } );
    } else if( has_category(‘surveys-research’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17145; //media id } );
    } else if( has_category(‘yelp’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17144; //media id } );
    } else if( has_category(‘people-culture-hwsi’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16759; //media id } );
    } else if( has_category(‘tlntmgmt’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17150; //media id } );
    } else if( has_category(‘train’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16742; //media id } );
    } else if( has_category(‘restaurant-notes’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17161; //media id } );
    } else if( has_category(‘business-2’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16782; //media id } );
    } else if( has_category(‘nso’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17064; //media id } );
    } else if( has_category(‘the-law’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17156; //media id } );
    } else if( has_category(‘govt-regs’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17156; //media id } );
    } else if( has_category(‘leadership-theory’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17154; //media id } );
    } else if( has_category(‘cost-controls-hwsi’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 16476; //media id } );
    } else if( has_category(‘technology-2’) ) {
    add_filter(‘dfi_thumbnail_id’, function () { return 17162; //media id } );
    }
    });

    Look ok?

    Thread Starter JeffreySummers

    (@jeffreysummers)

    I inserted in into the functions.php at the end…made the entire website go white. So I replaced the original file until you give me further instructions.

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    It’s my bad πŸ™ the // media id is replaced with /*media id*/

    add_action('template_redirect', function () {
    if ( has_category('10-things') ) {
    add_filter('dfi_thumbnail_id', function () { return 17158; /*media id*/ } );
    } else if( has_category('culinary') ) {
    add_filter('dfi_thumbnail_id', function () { return 17155; /*media id*/ } );
    } else if( has_category('foh') ) {
    add_filter('dfi_thumbnail_id', function () { return 17149; /*media id*/ } );
    } else if( has_category('holiday-posts') ) {
    add_filter('dfi_thumbnail_id', function () { return 17159; /*media id*/ } );
    } else if( has_category('hotel-notes') ) {
    add_filter('dfi_thumbnail_id', function () { return 17157; /*media id*/ } );
    } else if( has_category('travel-tuesday') ) {
    add_filter('dfi_thumbnail_id', function () { return 17147; /*media id*/ } );
    } else if( has_category('how-we-see-it') ) {
    add_filter('dfi_thumbnail_id', function () { return 17107; /*media id*/ } );
    } else if( has_category('coach') ) {
    add_filter('dfi_thumbnail_id', function () { return 16137; /*media id*/ } );
    } else if( has_category('consult') ) {
    add_filter('dfi_thumbnail_id', function () { return 17160; /*media id*/ } );
    } else if( has_category('podcasts') ) {
    add_filter('dfi_thumbnail_id', function () { return 17148; /*media id*/ } );
    } else if( has_category('pub-speak-facilitate') ) {
    add_filter('dfi_thumbnail_id', function () { return 16785; /*media id*/ } );
    } else if( has_category('qfo') ) {
    add_filter('dfi_thumbnail_id', function () { return 16789; /*media id*/ } );
    } else if( has_category('they-just-dont-get-it') ) {
    add_filter('dfi_thumbnail_id', function () { return 17153; /*media id*/ } );
    } else if( has_category('marketing-branding') ) {
    add_filter('dfi_thumbnail_id', function () { return 17151; /*media id*/ } );
    } else if( has_category('groupon') ) {
    add_filter('dfi_thumbnail_id', function () { return 17146; /*media id*/ } );
    } else if( has_category('guest-experience') ) {
    add_filter('dfi_thumbnail_id', function () { return 17143; /*media id*/ } );
    } else if( has_category('social-business') ) {
    add_filter('dfi_thumbnail_id', function () { return 17142; /*media id*/ } );
    } else if( has_category('surveys-research') ) {
    add_filter('dfi_thumbnail_id', function () { return 17145; /*media id*/ } );
    } else if( has_category('yelp') ) {
    add_filter('dfi_thumbnail_id', function () { return 17144; /*media id*/ } );
    } else if( has_category('people-culture-hwsi') ) {
    add_filter('dfi_thumbnail_id', function () { return 16759; /*media id*/ } );
    } else if( has_category('tlntmgmt') ) {
    add_filter('dfi_thumbnail_id', function () { return 17150; /*media id*/ } );
    } else if( has_category('train') ) {
    add_filter('dfi_thumbnail_id', function () { return 16742; /*media id*/ } );
    } else if( has_category('restaurant-notes') ) {
    add_filter('dfi_thumbnail_id', function () { return 17161; /*media id*/ } );
    } else if( has_category('business-2') ) {
    add_filter('dfi_thumbnail_id', function () { return 16782; /*media id*/ } );
    } else if( has_category('nso') ) {
    add_filter('dfi_thumbnail_id', function () { return 17064; /*media id*/ } );
    } else if( has_category('the-law') ) {
    add_filter('dfi_thumbnail_id', function () { return 17156; /*media id*/ } );
    } else if( has_category('govt-regs') ) {
    add_filter('dfi_thumbnail_id', function () { return 17156; /*media id*/ } );
    } else if( has_category('leadership-theory') ) {
    add_filter('dfi_thumbnail_id', function () { return 17154; /*media id*/ } );
    } else if( has_category('cost-controls-hwsi') ) {
    add_filter('dfi_thumbnail_id', function () { return 16476; /*media id*/ } );
    } else if( has_category('technology-2') ) {
    add_filter('dfi_thumbnail_id', function () { return 17162; /*media id*/ } );
    }
    });

    The rest of your code is valid. This should work.

    Thread Starter JeffreySummers

    (@jeffreysummers)

    Same result – site goes totally white, have to replace functions.php page with original….???

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    You need to add it to the functions.php. I know the code is correct. So the problem is probably somewhere in the functions.php. Can you share your whole functions.php I advise using http://pastebin.com/

    Thread Starter JeffreySummers

    (@jeffreysummers)

    I did add it. Got the white-out result. Here’s the pastebin link.

    http://pastebin.com/8vSyZHkG

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    its private, I cant see it

    Thread Starter JeffreySummers

    (@jeffreysummers)

    Should be able to now.

    Plugin Author janw.oostendorp

    (@janwoostendorp)

    http://pastebin.com/cTpJ2zFD

    An edited version which is error free. I suspect that you run an older version of php so I made the code to work with older versions.

    let me know πŸ˜‰

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Post Category’ is closed to new replies.