Display post attachments and custom Meta value for WordPress Gallery


<?php
function gallery() {
global $post, $posts;
?>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/jm_library/components/gallery/galleriffic/css/galleriffic-2.css" type="text/css" />
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/jm_library/components/gallery/galleriffic/js/jquery.galleriffic.js"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/jm_library/components/gallery/galleriffic/js/jquery.opacityrollover.js"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/jm_library/components/gallery/galleriffic/js/galleriffic.js"></script>
<?php
$images = get_children(array(
'post_parent'    => get_the_ID(),
'post_type'      => 'attachment',
'numberposts'    => -1, // show all
'post_status'    => null,
'post_mime_type' => 'image',
));
echo '<div id="gallery" class="content"><div id="controls" class="controls"></div><div class="slideshow-container"><div id="loading" class="loader"></div><div id="slideshow" class="slideshow"></div></div></div>';
echo '<div id="thumbs" class="navigation"><ul class="thumbs noscript" style="margin:0;">';
foreach($images as $image) {
$atturl   = wp_get_attachment_url($image->ID);
$source .= $atturl.',';
$at = rtrim($source, ',');
}
$image=get_post_meta($post->ID, 'images', true);
$img=explode(',',$image); 
for($i=0;$i<sizeof($img);$i++)
{ 
$source1 .= $img[$i].',';
$at1 = rtrim($source1, ',');
}
if(at == '')
{
$collect = $at1;
}
elseif($at1 == '')
{
$collect = $at;
}
elseif($at1 != '' && $at == '')
{
$collect = $at1;
}
else
{
$collect = $at.','.$at1;
}
$col=explode(',',$collect); 
for($i=0;$i<sizeof($col);$i++)
{
if(($col[$i] == substr($col[$i],0,57).''.'.jpg') || ($col[$i] == substr($col[$i],0,57).''.'_s.jpg') || ($col[$i] == substr($col[$i],0,57).''.'_b.jpg') || ($col[$i] == substr($col[$i],0,57).''.'_m.jpg')) {
echo '<li><a class="thumb" href="'.substr($col[$i],0,57).''.'_b.jpg'.'"><img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.substr($col[$i],0,57).''.'_s.jpg'.'&h=75&w=75&zc=1'.'"/></a>';
}
else
{
echo '<li><a class="thumb" href="'.$col[$i].'"><img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$col[$i].'&h=75&w=75&zc=1'.'"/></a>';
}
}
echo '</ul></div>';
}
add_shortcode('owngallery', 'gallery');
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s