WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP-Choose-Thumb] Display a "No Image Available" image when choosing a "None" Thumbnail (5 posts)

  1. eljkmw
    Member
    Posted 4 years ago #

    If there's anyone wanting to display a "No Image Available" image as a thumbnail when the 'none' thumbnail is chosen in a post, here's the following modification in wp-choose-thumb/wp-choose-thumb.php

    /**
     * Display thumb. For use in theme.
     * @param string $style style=""
     * @param integer $pid optional post id
     * @access public
     */
    function wct_display_thumb($style = '', $pid = '') {
    	global $post;
    	global $wct_plugin_url;
    
    	if('' == $pid){
    		if(null != $post) {
    			$pid = $post->ID;
    		} else {
    			return;
    		}
    	}
    
    	$src = trim(get_post_meta($pid, 'wct_thumb',true));
    
    	$alt = 'thumbnail';
    
    	$hasThumb = ('' != $src && 'none' != $src);
    
    	if($hasThumb) {
    		echo '<img alt="'.$alt.'" src="'. $src .'" class="alignleft" '.$style.'/>';
    	} else {
    		$src = $wct_plugin_url . '/resources/images/no-image.jpg';
    		echo '<img src="'. $src .'" class="alignleft" />';
    	}
    
    	return $hasThumb;
    }

    Remember to make a "No Image Available" image (e.g., no-image.jpg), and upload into the sub-directory '/resources/images' of the wp-choose-thumb plugin directory.

    Enjoy ...

    http://wordpress.org/extend/plugins/wp-choose-thumb/

  2. martinkoss
    Member
    Posted 4 years ago #

    That is something I've been trying to work out so I thank you for contributing that bit of code.

    I have a 'default' thumbnail already but couldn't figure out where to code it into the plugin.

    Cheers.

  3. martinkoss
    Member
    Posted 4 years ago #

    I want to take this a step further by adding a default image based on Category ID number.

    If anyone has any ideas on this - where I can code the if catID == x then... elseif catID == next cat then...

    I would appreciate it.

  4. magaworks
    Member
    Posted 4 years ago #

    Hi,
    I am using this plugin but I would like to know if anyone can tell me how can I crop the thumbnail. I thought the plugin did that by itself but I found out it does not. Can anyone help me with the code to do that?

  5. eljkmw
    Member
    Posted 3 years ago #

    If there's anyone wanting to display a "No Image Available" image as a thumbnail when the 'none' thumbnail is chosen in a post, here's the following modification in wp-choose-thumb/wp-choose-thumb.php

    This is for the update version 1.3.5.

    /**
     * Display thumb. For use in theme.
     * @param string $style style=""
     * @param integer $pid optional post id
     * @access public
     */
    function wct_display_thumb($style = '', $pid = '', $alt = 'thumbnail', $class = 'alignleft') {
    	global $post;
    	global $wct_plugin_url;
    
    	if('' == $pid){
    		if(null != $post) {
    			$pid = $post->ID;
    		} else {
    			return;
    		}
    	}
    
    	$src = trim(get_post_meta($pid, 'wct_thumb',true));
    
    	$hasThumb = ('' != $src && 'none' != $src);
    
    	if($hasThumb) {
    		echo '<img alt="'.$alt.'" src="'. $src .'" class="'.$class.'" '.$style.'/>';
    	} else {
    		$src = $wct_plugin_url . '/resources/images/no-image.jpg';
    		echo '<img src="'. $src .'" class="'.$class.'" />';
    	}
    
    	return $hasThumb;
    }

    Remember to make a "No Image Available" image (e.g., no-image.jpg), and upload into the sub-directory '/resources/images' of the wp-choose-thumb plugin directory.

    Enjoy ...

Topic Closed

This topic has been closed to new replies.

About this Topic