WordPress.org

Ready to get started?Download WordPress

Forums

TimThumb How to load only if image exists (1 post)

  1. Mr. Bigsby
    Member
    Posted 3 years ago #

    I've got timthumb in the theme I'm using, but I want to only load if the image exists and if not, have it not display.

    How would I go about doing this?

    Owner of the code pointed me to this section of code.

    function pong_posts($sort = 'recent', $items = 5, $echo = TRUE)
    {
    	$pp_blog_cat = get_option('pp_blog_cat');
    	$return_html = '';
    
    	if($sort == 'recent')
    	{
    		$posts = get_posts('numberposts='.$items.'&order=DESC&orderby=date&post_status=publish');
    		$title = 'Recent Posts';
    	}
    	else
    	{
    		global $wpdb;
    
    		$posts = $wpdb->get_results("SELECT comment_count, ID, post_title, post_content, post_date FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY comment_count DESC LIMIT 0 , ".$items);
    		$title = 'Popular Posts';
    	}
    
    	if(!empty($posts))
    	{
    
    		$return_html.= '<h4 class="widgettitle">'.$title.'</h4><hr/>';
    		$return_html.= '<ul class="posts blog">';
    
    			foreach($posts as $post)
    			{
    				$image_thumb = get_post_meta($post->ID, 'blog_thumb_image_url', true);
    				$return_html.= '<li><a href="'.get_permalink($post->ID).'"><img src="'.get_bloginfo( 'stylesheet_directory' ).'/timthumb.php?src='.$image_thumb.'&h=60&w=60&zc=1" alt="" /></a><h6><a href="'.get_permalink($post->ID).'">';
    				$return_html.= pong_substr($post->post_title, 50).'</a></h6><a href="'.gen_permalink(get_permalink($post->ID), 'quick_view=1').'" class="quick_view" title="Quick View"><img src="'.get_bloginfo( 'stylesheet_directory' ).'/images/icon_quick_view.png" style="width:16px" class="mid_align"/></a>'.date('F j, Y', strtotime($post->post_date)).'<br/><br/>';
    				$return_html.= pong_substr(strip_tags(strip_shortcodes($post->post_content)), 80).'</li>';
    
    			}	
    
    		$return_html.= '</ul>';
    
    	}
    
    	if($echo)
    	{
    		echo $return_html;
    	}
    	else
    	{
    		return $return_html;
    	}
    }
    
    function pong_cat_posts($cat_id = '', $items = 5, $echo = TRUE)
    {
    	$return_html = '';
    	$posts = get_posts('numberposts='.$items.'&order=DESC&orderby=date&category='.$cat_id);
    	$title = get_cat_name($cat_id);
    
    	if(!empty($posts))
    	{
    
    		$return_html.= '<h4 class="widgettitle">'.$title.'</h4><hr/>';
    		$return_html.= '<ul class="posts">';
    
    			foreach($posts as $post)
    			{
    				$image_thumb = get_post_meta($post->ID, 'blog_thumb_image_url', true);
    				$return_html.= '<li><img src="'.get_bloginfo( 'stylesheet_directory' ).'/timthumb.php?src='.$image_thumb.'&h=60&w=60&zc=1" alt="" /> <a href="'.get_permalink($post->ID).'">';
    				$return_html.= '<h6>'.pong_substr($post->post_title, 50).'</h6></a><a href="'.gen_permalink(get_permalink($post->ID), 'quick_view=1').'" class="quick_view" title="Quick View"><img src="'.get_bloginfo( 'stylesheet_directory' ).'/images/icon_quick_view.png" style="width:16px" class="mid_align"/></a>'.get_the_date().'<br/><br/>';
    				$return_html.= pong_substr(strip_tags(strip_shortcodes($post->post_content)), 80).'</li>';
    
    			}	
    
    		$return_html.= '</ul>';
    
    	}
    
    	if($echo)
    	{
    		echo $return_html;
    	}
    	else
    	{
    		return $return_html;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic