• I need to edit the piece of code below from my post_images.php file so that the post image in the post image custom field has the option of linking to an external url instead of linking to the single post page (which is the default as per code below) – i need to edit this long function somehow so as to achieve the above. All help appreciated ??

    <?php
    
    function thesis_post_image_info($type = 'image') {
    	global $post, $thesis_design, $blog_id;
    
    	$image_string = ($type == 'image') ? 'post_image' : 'thumb';
    	$image_url = get_post_meta(get_the_id(), 'thesis_' . $image_string, true);
    
    	$post_image['type'] = $type;
    
    	if ($type == 'thumb' && $image_url != '') {
    		$post_image['show'] = true;
    		$post_image['url'] = $image_url;
    		$post_image['resize'] = false;
    	}
    	elseif ($type == 'thumb') {
    		$image_url = get_post_meta(get_the_id(), 'thesis_post_image', true);
    
    		if ($image_url != '') {
    			$post_image['show'] = true;
    			$post_image['url'] = $image_url;
    			$post_image['resize'] = true;
    		}
    		else
    			$post_image['show'] = false;
    	}
    	elseif ($image_url != '') {
    		$post_image['url'] = $image_url;
    		$post_image['resize'] = false;
    	}
    
    	if ($type == 'image' && (isset($post_image['url']) && strlen($post_image['url']) !== 0)) {
    		$post_image['show'] = ((is_single() && !$thesis_design->image['post']['single']) || (is_archive() && !$thesis_design->image['post']['archives'])) ? false : true;
    
    		if ($post_image['show']) {
    			$image_vertical_override = get_post_meta(get_the_id(), 'thesis_post_image_vertical', true);
    			$post_image['y'] = ($image_vertical_override) ? $image_vertical_override : $thesis_design->image['post']['y'];
    			$image_horizontal_override = get_post_meta(get_the_id(), 'thesis_post_image_horizontal', true);
    			$post_image['x'] = ($image_horizontal_override != '') ? $image_horizontal_override : $thesis_design->image['post']['x'];
    			$frame_override = get_post_meta(get_the_id(), 'thesis_' . $image_string . '_frame', true);
    			$post_image['frame'] = ($frame_override != '' && $frame_override != $thesis_design->image['post']['frame']) ? $frame_override : $thesis_design->image['post']['frame'];
    		}
    	}
    	elseif ($type == 'thumb' && isset($post_image['url']) && $post_image['url'] != '') {
    		$thumb_vertical_override = get_post_meta(get_the_id(), 'thesis_thumb_vertical', true);
    		$post_image['y'] = ($thumb_vertical_override) ? $thumb_vertical_override : $thesis_design->image['thumb']['y'];
    		$image_horizontal_override = get_post_meta(get_the_id(), 'thesis_thumb_horizontal', true);
    		$post_image['x'] = ($image_horizontal_override != '') ? $image_horizontal_override : $thesis_design->image['thumb']['x'];
    		$frame_override = get_post_meta(get_the_id(), 'thesis_' . $image_string . '_frame', true);
    		$post_image['frame'] = ($frame_override != '' && $frame_override != $thesis_design->image['thumb']['frame']) ? $frame_override : $thesis_design->image['thumb']['frame'];
    	}
    	else
    		$post_image['show'] = false;
    
    	if ($post_image['show'] && $post_image['url'] != '') {
    		$upload_info = home_url();
    		$path_match = preg_match("|{$upload_info}|i", $post_image['url']);
    		if ($thesis_design->image['fopen'] && empty($path_match))
    			$image_path = $post_image['url'];
    		elseif (is_multisite() && $blog_id > 1) {
    			/* making some assumptions about the structure of the uploads in ms */
    			$upload_a = wp_upload_dir();
    			$upload_b = preg_split('/files/i', $post_image['url']);
    			if (@file_exists("{$upload_a['basedir']}{$upload_b[1]}"))
    				$image_path = "{$upload_a['basedir']}{$upload_b[1]}";
    		}
    		else {
    			$site_info = parse_url(home_url());
    			$recon_site = "{$site_info['scheme']}://{$site_info['host']}";
    			$base = preg_quote($recon_site, '/');
    			$path = preg_split("/$base/i", $post_image['url']);
    			$image_path = ABSPATH . $path[1];
    			if (! @file_exists($image_path)) // look one directory down if we didn't find it
    				$image_path = @file_exists(dirname(ABSPATH) . $path[1]) ? dirname(ABSPATH) . $path[1] : false;
    		}
    
    		$post_image['alt'] = get_post_meta(get_the_id(), 'thesis_' . $image_string . '_alt', true);
    
    		if (@getimagesize($image_path)) {
    
    			$image['class'] = thesis_get_image_classes($post_image);
    			$image['attributes'] = thesis_image_attributes($post_image);
    
    			if ($post_image['alt'] != '')
    				$image['alt'] = $post_image['alt'];
    			elseif ($type == 'thumb')
    				$image['alt'] = 'Thumbnail image for ' . get_the_title();
    			else
    				$image['alt'] = 'Post image for ' . get_the_title();
    
    			if (is_single() || is_page()) {
    				$open_link = '';
    				$close_link = '';
    			}
    			else {
    				$open_link = '<a class="post_image_link" href="' . get_permalink() . '" title="Permanent link to ' . get_the_title() . '">';
    				$close_link = '</a>';
    			}
    
    			$post_image['output'] = $open_link . '<img ' . $image['class'] . $image['attributes'] . ' alt="' . $image['alt'] . '" />' . $close_link . "\n";
    		}
    	}
    
    	return $post_image;
    }
  • The topic ‘Linking Post Image to External URL’ is closed to new replies.