#duaharithemes is awur-awuran wordpress themes

Get all image attachment from post wordpress with a variety of sizes


Kita dapat mengambil semua image yang ada pada post yang telah kita publish dengan berbagai macam ukuran dengan cara :

$images =& get_children( array (
     'post_parent' => $post->ID,
     'post_type' => 'attachment',
     'post_mime_type' => 'image'
));
if ( !empty($images) ) :
   foreach ( $images as $attachment_id => $attachment ) :
      $image_gallery_thumb = wp_get_attachment_image_src( $attachment_id, 'img-thumbnail', false );
      $image_gallery_full = wp_get_attachment_image_src( $attachment_id, 'big-thumbnail', false );
?>
      <div class="gallery-single-item">
         <a href="<?php echo $image_gallery_full[0]; ?>" class="gallery-images">
           <img src="<?php echo $image_gallery_thumb[0]; ?>">
         </a>
      </div>
<?php
   endforeach;
endif;

img-thumbnail dan big-thumbnail adalah ukuran yang sudah di deklarasikan sebelumnya, contohnya :

if ( function_exists( 'add_image_size' ) ) :
        add_image_size( 'big-thumbnail', 1140, 637,true );
        add_image_size( 'img-thumbnail', 560, 375,true );
endif;

Published by

Avriqq

Hello. I'm junior web designer. I love bootstrap and i'm wordpress enthusiast too.

Leave a comment