Return to Snippet

Revision: 17289
at September 19, 2009 12:20 by tylersticka


Updated Code
<?php 
// http://tylersticka.com/2009/09/wcpdx09/
// Retrieve custom meta for this item
$fields = get_post_custom();

// If the gallery key exists, let's show some gallery functionality
if (isset($fields['gallery'])) {

	// Split the comma-separated gallery meta value into an array 
	$images = split(',',$fields['gallery'][0]);
	
	// Grab the current WordPress page and use it as the current
	// gallery item (defaults to 1)
	$current = ($paged == '') ? 1 : $paged;
	
	// Grab the current image from the array
	$image = $images[$current-1];
	
	// Display the current gallery image with intelligent alt text 
?>
<div id="gallery">
	<img src="<?php echo $image; ?>" alt="<?php echo "Image $current of ".count($images); ?>" />
	<?php 
	// Only show "next" and "back" controls if there's more 
	// than one gallery item
	if (count($images) > 1) {
	?>
	<ul>
		<?php if ($current > 1) { ?><li class="prev"><a href="<?php the_permalink() ?>page/<?php echo $current-1; ?>">Previous Image</a></li><?php } ?>
		<?php if ($current < count($images)) { ?><li class="next"><a href="<?php the_permalink() ?>page/<?php echo $current+1; ?>">Next Image</a></li><?php } ?>
	</ul>
	<?php } ?>
</div>
<?php } ?>

Revision: 17288
at August 30, 2009 17:28 by tylersticka


Updated Code
<?php 
// Retrieve custom meta for this item
$fields = get_post_custom();

// If the gallery key exists, let's show some gallery functionality
if (isset($fields['gallery'])) {

	// Split the comma-separated gallery meta value into an array 
	$images = split(',',$fields['gallery'][0]);
	
	// Grab the current WordPress page and use it as the current
	// gallery item (defaults to 1)
	$current = ($paged == '') ? 1 : $paged;
	
	// Grab the current image from the array
	$image = $images[$current-1];
	
	// Display the current gallery image with intelligent alt text 
?>
<div id="gallery">
	<img src="<?php echo $image; ?>" alt="<?php echo "Image $current of ".count($images); ?>" />
	<?php 
	// Only show "next" and "back" controls if there's more 
	// than one gallery item
	if (count($images) > 1) {
	?>
	<ul>
		<?php if ($current > 1) { ?><li class="prev"><a href="<?php the_permalink() ?>page/<?php echo $current-1; ?>">Previous Image</a></li><?php } ?>
		<?php if ($current < count($images)) { ?><li class="next"><a href="<?php the_permalink() ?>page/<?php echo $current+1; ?>">Next Image</a></li><?php } ?>
	</ul>
	<?php } ?>
</div>
<?php } ?>

Revision: 17287
at August 30, 2009 17:27 by tylersticka


Updated Code
<?php 
// Retrieve custom meta for this item
$fields = get_post_custom();

// If the gallery key exists, let's show some gallery functionality
if (isset($fields['gallery'])) {

	// Split the comma-separated gallery meta value into an array 
	$images = split(',',$fields['gallery'][0]);
	
	// Grab the current WordPress page and use it as the current
	// gallery item (defaults to 1)
	$current = ($paged == '') ? 1 : $paged;
	
	// Grab the current image from the array
	$image = $images[$current-1];
	
	// Display the current gallery image with intelligent alt text 
?>
	<div id="gallery">
		<img src="<?php echo $image; ?>" alt="<?php echo "Image $current of ".count($images); ?>" />
		<?php 
		// Only show "next" and "back" controls if there's more 
		// than one gallery item
		if (count($images) > 1) {
		?>
		<ul>
			<?php if ($current > 1) { ?><li class="prev"><a href="<?php the_permalink() ?>page/<?php echo $current-1; ?>">Previous Image</a></li><?php } ?>
			<?php if ($current < count($images)) { ?><li class="next"><a href="<?php the_permalink() ?>page/<?php echo $current+1; ?>">Next Image</a></li><?php } ?>
		</ul>
		<?php } ?>
	</div>
<?php } ?>

Revision: 17286
at August 30, 2009 17:27 by tylersticka


Updated Code
<?php 
// Retrieve custom meta for this item
$fields = get_post_custom();

// If the gallery key exists, let's show some gallery functionality
if (isset($fields['gallery'])) {

	// Split the comma-separated gallery meta value into an array 
	$images = split(',',$fields['gallery'][0]);
	
	// Grab the current WordPress page and use it as the current
	// gallery item (defaults to 1)
	$current = ($paged == '') ? 1 : $paged;
	
	// Grab the current image from the array
	$image = $images[$current-1];
	
	// Display the current gallery image with intelligent alt text ?>
	<div id="gallery">
		<img src="<?php echo $image; ?>" alt="<?php echo "Image $current of ".count($images); ?>" />
		<?php 
		// Only show "next" and "back" controls if there's more 
		// than one gallery item
		if (count($images) > 1) {
		?>
		<ul>
			<?php if ($current > 1) { ?><li class="prev"><a href="<?php the_permalink() ?>page/<?php echo $current-1; ?>">Previous Image</a></li><?php } ?>
			<?php if ($current < count($images)) { ?><li class="next"><a href="<?php the_permalink() ?>page/<?php echo $current+1; ?>">Next Image</a></li><?php } ?>
		</ul>
		<?php } ?>
	</div>
<?php } ?>

Revision: 17285
at August 30, 2009 17:23 by tylersticka


Initial Code
<?php 
// Retrieve custom meta for this item
$fields = get_post_custom();

// If the gallery key exists, let's show some gallery functionality
if (isset($fields['gallery'])) {

	// Split the comma-separated gallery meta value into an array 
	$images = split(',',$fields['gallery'][0]);
	
	// Grab the current WordPress page and use it as the current
	// gallery item (defaults to 1)
	$current = ($paged == '') ? 1 : $paged;
	
	// Grab the current image from the array
	$image = $images[$current-1];
	
	// Display the current gallery image with intelligent alt text 
?>
	<div id="gallery">
		<img src="<?php echo $image; ?>" alt="<?php echo "Image $current of ".count($images); ?>" />
		<?php 
		// Only show "next" and "back" controls if there's more 
		// than one gallery item
		if (count($images) > 1) {
		?>
		<ul>
			<?php if ($current > 1) { ?><li class="prev"><a href="<?php the_permalink() ?>page/<?php echo $current-1; ?>">Previous Image</a></li><?php } ?>
			<?php if ($current < count($images)) { ?><li class="next"><a href="<?php the_permalink() ?>page/<?php echo $current+1; ?>">Next Image</a></li><?php } ?>
		</ul>
		<?php } ?>
	</div>
<?php } ?>

Initial URL
http://tylersticka.com/2009/09/wcpdx09/

Initial Description
For use within The Loop, in your portfolio item page template.

Initial Title
WordPress-Powered Portfolios: Gallery

Initial Tags
wordpress

Initial Language
PHP