• Dear @janwoostendorp,

    First of all, great plugin! Now I wanted to know if there’s a way to define a specific feature image for a CPT archive? I got it to work fine for the CPT posts, but I haven’t found a way yet to get it to work for the archive itself. Is that possible?

    Kind regards, Philip

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

    (@janwoostendorp)

    Hi Strothi,

    Yes that’s possible with a little extra code.
    There are several examples in the FAQ: https://www.ads-software.com/plugins/default-featured-image/#faq

    Let me know if you need any help with the code.

    Jan-Willem

    Thread Starter Strothi

    (@strothi)

    Dear @janwoostendorp,

    Thanks, I checked the FAQ and got it to work for the post types as outlined in the FAQ, but not for the archive page. For posts, pages and categories it’s all clear, but how can I target archives?

    Kind regards, Philip

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Thread Starter Strothi

    (@strothi)

    Dear @janwoostendorp,

    Thanks for the links. I’m not really a programmer myself, but I tried anyhow. Seeing that is_archive() does not accept any parameters, I tried multiple variations of getting is_post_type_archive() to work, but haven’t been successful so far. I modeled my code after the code that works for the CPT:

    function dfi_posttype_archive ( $dfi_id, $post_id ) {
      $post = get_post($post_id);
      if (is_post_type_archive( $post_types = 'papers') ) {
        return 19583; // the image id
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_archive', 10, 2 );

    But it doesn’t work and neither have my other tries, hence I would really appreciate a lot if you could help me out here!

    Thanks a lot in advance.

    Kind regards, Philip

    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello Strothi,

    That’s not a problem. This will set 19583 as the DFI on the archive url of papers.

    function dfi_posttype_archive ( $dfi_id, $post_id ) {
      if (is_post_type_archive( 'papers') ) {
        return 19583; // the image id
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_archive', 10, 2 );

    Let me know how it goes and if you need any help.

    • This reply was modified 3 years, 1 month ago by Jan-Willem.
    Thread Starter Strothi

    (@strothi)

    Dear @janwoostendorp,

    Unfortunately, it doesn’t – I had tried that also before, but it’s unfortunately not working. I noticed though that I also don’t get any feature image that I set with your plugin for e.g. my blog post page or any other archive?!

    It works fine for posts / cpts without a featured image as well as for pages, but I don’t get it to work on archive pages, neither for specific archives, nor for any archives in general?!

    Kind regards, Philip

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘DFI for CPT Archive’ is closed to new replies.