• Resolved gnfb

    (@gnfb)


    If only you could select the featured image based on the category of the post???

Viewing 1 replies (of 1 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello gnfb,

    This is by design. Because that will raise a lot of questions. Like:

    What if there are multiple categories set?
    Should a parent or a child prioritize?
    What about tags, or custom taxonomies.

    I don’t want to make those decisions, because they will be different for everybody.
    But I did implement a way to do this yourself with a bit of coding.
    Below is the example I have in the FAQ.

    function dfi_category ( $dfi_id, $post_id ) {
      // all which have 'animals' as a category
      if ( has_category( 'animals', $post_id ) ) {
    
        //sub category
        if ( has_category( 'cats', $post_id ) ) {
          return 7; // cats img
        } else if has_category( 'dogs', $post_id ) {
          return 8; // dogs img
        }
    
        return 6; // default animals picture
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );

    Hope this helps.
    Let me know if I could do anything else to help, or if I could help with this code.

Viewing 1 replies (of 1 total)
  • The topic ‘Great plugin but!’ is closed to new replies.