Posts Tagged image crop

Image gallery(thumbnails) with WordPress image cropping

What about creating a small gallery of linked thumbnails, based on images inserted in a post, with cropping thumbnails?

First, create a post on WordPress and choose a category, for example, “tour”.
Then you can insert as many images as you want, defining links as you want.
You can use a custom field, to manage the title of the galery.

Publish you post, and call it on your PHP page, using the code bellow(where you can choose the number of images of your gallery and the cropping dimensions):

if (have_posts()) : 
 global $post;
 $myposts = get_posts('numberposts=1&category_name=tour');
 foreach($myposts as $post) :
	// # here you call a custom field on wordpress
	$tourdes = get_post_meta($post->ID, 'Descrip', true);
	<div id="thumbs">            	
		$args = array(
			'post_type' => 'attachment',
			'numberposts' => -1,
			'post_status' => null,
			'post_parent' => $post->ID
		$attachments = get_posts($args);
		if ($attachments) {
			// - $tot_img : the total number of thumbnails on the gallery
			// - $brk_lin : number of image on each line
			foreach ($attachments as $attachment) {						
			  // # here we define the max number of images
			  if(intval($cnt_img) < $tot_img){							
				echo "<span style='padding-left:3px'>";
				$imgref = wp_get_attachment_url($attachment->ID);
				$imgsrc = wp_get_attachment_image($attachment->ID, array(40,40), $icon = false);
				echo "<a href=".$imgref.">". $imgsrc ."<a>";
				echo "</span>"."\n";							
				// # here we define the line break
				 echo "<br>";	
<? endforeach;
endif; ?>



%d bloggers like this: