• itsJulian

    (@itsjulian)


    Hi, I have 6 different post categories, which I would like to use individual default featured images. Is there a way to accomplish this?

    Thank you,
    Julian

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

    (@janwoostendorp)

    Hi Jullian,

    That is very much possible with a little bit of code.
    Create the file: wp-content/plugins/dfi-catagory-images.php
    Add the following code to that file, and change the category slugs and set the correct media/image ids:

    
    <?php
    /**
     * Plugin Name:       Default Featured Image, different images per category
     * Plugin URI:        https://www.ads-software.com/support/topic/different-feature-images-for-different-post-categories/
     * Version:           1.0
     */
    
    function dfi_category ( $dfi_id, $post_id ) {
    	// The category slug change per category.
    	if ( has_category( 'cat', $post_id ) ) {
    		return 7; // cat img id.
    	} elseif ( has_category( 'dog', $post_id ) ) {
    		return 8; // dog img id.
    	} elseif ( has_category( 'fish', $post_id ) ) {
    		return 9; // fish img id.
    	} elseif ( has_category( 'chicken', $post_id ) ) {
    		return 10; // chicken img id.
    	} elseif ( has_category( 'rhino', $post_id ) ) {
    		return 11; // rhino img id.
    	} elseif ( has_category( 'pikachu', $post_id ) ) {
    		return 12; // pikachu img id.
    	} elseif ( has_category( 'snail', $post_id ) ) {
    		return 13; // snail img id.
    	}
    	return $dfi_id; // the original featured image id.
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
    

    Don’t forget the activate the plugin after creating it.
    Let me know how it goes!

    Jan-Willem

    Not sure why he hasn’t replied back.. though i just wanted to say i was looking for the exact same thing and the code works perfectly ??
    thanks!

    btw for users out there as stated above put the .php file in the plugins folder not inside “Default featured image” folder or it will detect it as an old version of the plugin and requests you to update it.

    • This reply was modified 2 years, 11 months ago by jameshallow1.
    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi James,

    Glad to heat this helped.

    Hello Jan-Willem

    I’m glad I found this post and I try to get it working.
    If for example the media id is post=920 where do I put it in your PHP file?
    Like this (not working)?
    if ( has_category( ‘Algemeen’, $920_id ) ) {
    return 7; // Algemeen img id.

    Thans for helping me!
    Otto Munters

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Different feature images for different post categories’ is closed to new replies.