TODO: To change the header's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
×
Menu
Index

Truy xuất tất cả các ảnh thêm vào post

 
Bạn có thể tạo gallery cho bài viết, trang..(custom post type) bằng cách sử dụng các thư viện jquery bên ngoài. Để thực hiện chúng ta sẽ lấy tất cả các hình ảnh được chèn vào bài viết.
Lấy mảng danh sách các image attachments thuộc về post/page:
<?php
     $images =& get_children( array (
          'post_parent' => $post->ID,
          'post_type' => 'attachment',
          'post_mime_type' => 'image'
     ));
 
     if ( empty($images) ) {
          // no attachments here
     } else {
          foreach ( $images as $attachment_id => $attachment ) {
               echo wp_get_attachment_image( $attachment_id, 'thumbnail' );
          }
     }
?>
 
Note: Vì attachment bao gồm: image, zip, pdf,.audio file. Ở đây chúng ta chỉ lấy image.
 
 
Made with help of Dr.Explain

Unregistered version