WordPress.org

Ready to get started?Download WordPress

Forums

Default featured image
[resolved] Category Featured Image not working fully (10 posts)

  1. rjt1985
    Member
    Posted 1 year ago #

    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 - dev.rjthompsonmusic.com

    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 - http://dev.rjthompsonmusic.com/category/social/twitter/

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

    Many thanks,

    R

    http://wordpress.org/extend/plugins/default-featured-image/

  2. janw.oostendorp
    Member
    Plugin Author

    Posted 1 year ago #

    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 ;)

  3. rjt1985
    Member
    Posted 1 year ago #

    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">',
    					get_template_directory_uri());
    			}
    
    			// 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: http://dev.rjthompsonmusic.com/tour/

    Any idea why that would be too?

    Many thanks for the quick reply.

    R

  4. janw.oostendorp
    Member
    Plugin Author

    Posted 1 year ago #

    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!

  5. rjt1985
    Member
    Posted 1 year ago #

    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?

  6. janw.oostendorp
    Member
    Plugin Author

    Posted 1 year ago #

    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

  7. rjt1985
    Member
    Posted 1 year ago #

    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).

  8. janw.oostendorp
    Member
    Plugin Author

    Posted 1 year ago #

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

    And see it it fixes that

  9. rjt1985
    Member
    Posted 1 year ago #

    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.

  10. janw.oostendorp
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic