Simple wordpress image gallery v2, using jQuery lightbox plugin, part2

So here we are, we’ve got a function that get attached picture from a post and their thumbnails url. Now what? First I forgot to mention that this function should be pasted in the function.php file on your current template folder. If you haven’t got one just create a blank php file and name it ‘function’.

This file gets included across all the wordpress site so you can call what’s in there at any time.

The next part is displaying our pictures where they belong to, the post. To do that we need to modify either the index.php /single.php. Or if you are using custom template, modify the templates accordingly.

In The Loop in our php files we need to add some code that will call the getGallery function passing it the id of the post we are on and process the array returned to print out some images.

The template code:

//don't bother doing anything if there are no images to show
<?php if($images = getGallery($post->ID)): ?>
				
	<div class="gallery">
		<ul>
			<?php 
			//for each image in the array print a <li> <a> <img> sequence with the correct information in them
			foreach($images as $image)
			{
				$image['meta_value'] = apply_filters( 'wp_get_attachment_metadata', maybe_unserialize($image['meta_value']), $post->ID );
				$thumb = $output['sizes']['thumbnail']['file'];
				$url = str_replace(basename($output['file']), basename($thumb), $output['file']);
	
				echo '<li><a href="'.$image['guid'].'"><img src="'.get_option('upload_path').'/'.$url.'" alt="'.$image['post_name'].'" /></a></li>';
			}
						
			?>
		</ul>
	</div>
<?php endif; ?>

So you refresh your page with this template you will see all attached images displayed. Next step, hook the javascript(part 3 of this tutorial). See you soon.

2 responses to “Simple wordpress image gallery v2, using jQuery lightbox plugin, part2”

Leave a Reply

  1. Simple wordpress image gallery v2, using jQuery lightbox plugin, part3 | Your Site is Valid Blog

    [...] Part 2: process attachment in template [...]

  2. Simple wordpress image gallery v2, using jQuery lightbox plugin | Your Site is Valid Blog

    [...] now got a function that returns an array full of all the stuff we need to get started. Next the template loop (part 2 of this [...]

Theme Forest ad
Wordpress Themes Collection ad
Woothemes

Poll

How do you start your WordPress plugins development projects?

View Results

Loading ... Loading ...