How to display custom wordpress gallery images from post attachment
The
[gallery]
shortcode is used in a Post or Page to display a thumbnail gallery of images attached to that post. Or You can use like this: <table cellspacing="0" cellpadding="5" align="left">
<tbody>
<tr>
<?php
$images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
if ($images) {
$size = 'thumbnail';
$num_of_images = count($images);
foreach ($images as $image) {
$img_title = $image->post_title; // title.
$img_description = $image->post_content; // description.
$img_caption = $image->post_excerpt; // caption.
$img_url = wp_get_attachment_url($image->ID); // url of the full size image.
$preview_array = image_downsize( $image->ID, $size );
$img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
?>
<td valign="top">
<a class="lightwindow" href="<?php echo $img_url; ?>" rel="example1"><img class="alignleft size-full wp-image-911" title="<?php echo $img_title; ?>" src="<?php echo $img_preview; ?>" alt="<?php echo $img_caption; ?>" width="100" height="100" /></a>
</td>
<?php
}
}?>
</tr>
</tbody>
</table>
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.