Support » Plugin: Default featured image » Category Featured Image not working fully

  • Resolved rjt1985


    Hi there,

    I’ve utilised your code to set the default featured image of a category…

    function dfi_category( $dfi_id ) {
            if ( has_category( 'twitter' ) ) {
                return 728;
            } else if ( has_category( 'facebook' ) ) {
                return 603; // the image id
            return $dfi_id; // the original featured image id
        add_filter('dfi_thumbnail_id', 'dfi_category' );

    It works in the loop of my posts, but it isn’t displaying that in the sidebar for some reason, at least not on the homepage.

    For example, here on the homepage you’ll see a post called Twitter Test in the main bulk of the page –

    That is showing the correct featured image.

    However, in the sidebar, where it shows the Latest Tweets, it has the main default featured image for some reason.

    As an additional spanner in the works, on the Twitter Category page itself, it works fine in both the posts and the sidebar –

    Any idea what I’d have to tweak to get it to work in the homepage sidebar?

    Many thanks,


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


    Hi thomos, right now I see the default camera picture on everything twitter related post/sidebar.

    Can you give the code that displays that thumbnail in the sidebar?
    Pretty sure we can figure this one out 😉

    Hi there,

    Thanks for the swift reply. I had actually deactivated the plugin temporarily while I searched for a solution.

    If you look now, you will see the problem I was referring to in the OP.

    The code that displays the thumbnail on the homepage sidebar is:

    // Get posts
    		$posts = get_posts($args);
    		// Check if we have posts
    		if ( !$posts ) return '';
    		// Start posts list
    		$output = sprintf('<ul id="tab-recent-%s" class="list-recent wpb-tab">', $wid);
    		// Loop through posts
    		foreach ( $posts as $post ) {
    			// Set post id, date, format, link, thumbnail, title
    			$id = $post->ID;
    			$date = get_the_time(get_option('date_format'), $id);
    			$format = 'format-'.get_post_format($id);
    			$link = get_permalink($id);
    			$title = get_the_title($id);
    			$thumb = get_the_post_thumbnail($id, 'size-thumbnail-tabs');
    			// Set placeholder thumbnail, if none set
    			if ( !$thumb && $opts['recent-thumb'] ) {
    				$thumb = sprintf('<img src="%s/img/widgets/tabs-thumb.jpg">',
    			// Set classes
    			$classes = $format;
    			if ( $thumb && $opts['recent-thumb'] ) $classes .= ' wpb-thumb-enabled';
    			// Build post list item
    			$output .= sprintf('<li class="%s group">', $classes);
    			$output .= sprintf('<a title="%1$s" href="%2$s">', $title, $link);
    			// Check for post thumbnail
    			if ( $thumb && $opts['recent-thumb'] ) {
    				$output .= '<span class="wpb-thumb">';
    				$output .= $thumb;
    				if ( in_array($format, array('format-audio','format-video')) )
    					$output .= '<i class="icon-thumb"></i>';
    				$output .= '</span>';
    			$output .= '<span class="wpb-text">';
    			$output .= sprintf('<i class="title">%s</i>', $title);
    			$output .= sprintf('<i class="meta">%s</i>', $date);
    			$output .= '</span></a></li>';
    		// End posts list

    Also, for some reason, where your plugin is enabled, I’m getting the default image with some completely unrelated text over it displaying on static pages at the top… see here:

    Any idea why that would be too?

    Many thanks for the quick reply.


    Plugin Author janw.oostendorp


    I would suggest not renaming $posts en $post.

    $post is a global wordpress uses so When you set the $id with $post->ID It probably uses the global $post which is then overall page.

    Let me know!

    I shouldn’t really change that because it is all linked into the theme I’m using. It could open a massive can of worms!

    Is there nothing I can add/alter with your code?

    Plugin Author janw.oostendorp


    Can you at least try it?
    Just to confirm if this really is the problem?
    You can always put it back.

    Or just var_dump() the $id? to check if you really get the wrong ID

    I’ll give it a go later. If you could be more specific on how exactly to do these things it would be very helpful (I don’t really know php).

    Plugin Author janw.oostendorp


    In the piece of code change all your $posts to $sidebar_posts and $post to $sidebar_post

    And see it it fixes that

    I’ve just tried that, and it’s still showing up with the same problem.

    Any ideas?

    Thanks for the help by the way. Really appreciate it.

    Plugin Author janw.oostendorp


    sorry for the late response.
    For some reason it gets the wrond ID, it most likely isn’t the fault of the plugin. Still I wanna know for sure.

    Where is $args filled? and what is in it there it is going wrong.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Category Featured Image not working fully’ is closed to new replies.