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

Gallery Metabox

 
Download và kích hoạt plugin gallery metabox tại địa chỉ: https://wordpress.org/plugins/gallery-metabox/
Sau khi kích hoạt mục Gallery metabox sẽ xuất hiện trong giao diện chỉnh sửa mỗi post/page.
Nếu không thấy xuất hiện mục này bạn check vào tùy chọn Gallery Images ở phần screen options.
 
Sử dụng:
*Lấy gallery ảnh của page/post:
<?php
global $BE_Gallery_Metabox;
$images=$BE_Gallery_Metabox->gallery_images($post->ID);
print_r($images);
?>
 
Actions/Filters:
 
* Thay thế nút upload ảnh của plugin:
Sửa đổi/thay thế các nút quản lý ảnh: Upload Images, Manage Gallery, Update Gallery sử dụng filter 'be_gallery_metabox_intro'.
add_filter( 'be_gallery_metabox_intro', 'sample_change_gallery_metabox_intro' );
/**
* Change Gallery Metabox Intro
* @author Bill Erickson
* @link http://www.billerickson.net/code/gallery-metabox-change-intro-text
*
* @param string $intro
* @return string
*/
function sample_change_gallery_metabox_intro( $intro ) {
     $intro = '<p><a href="media-upload.php?post_id=' . $post->ID .'&amp;type=image&amp;TB_iframe=1&amp;width=640&amp;height=715" id="add_image" class="thickbox" title="Add Image">Upload Images</a> | <a href="media-upload.php?post_id=' . $post->ID .'&amp;type=image&amp;tab=gallery&amp;TB_iframe=1&amp;width=640&amp;height=715" id="manage_gallery" class="thickbox" title="Manage Gallery">Manage Gallery</a></p>';
     echo $intro;
}
 
* Hỗ trợ custom post type:
Mặc định plugin chỉ áp dụng cho post/page, nếu muốn cài cho các post type khác trong wordpress bạn khai báo trong filter 'be_gallery_metabox_post_types'.
Khai báo sử dụng Gallery images cho các custom post type, ví dụ mình sử dụng gallery images cho kiểu ‘page’,’post’, và custom post type ‘rotator’.
<?php
 
/**
* Gallery Metabox - Only show on 'page' and 'rotator' post types
* @author Bill Erickson
* @link http://www.wordpress.org/extend/plugins/gallery-metabox
* @link http://www.billerickson.net/code/gallery-metabox-custom-post-types
* @since 1.0
*
* @param array $post_types
* @return array
*/
function be_gallery_metabox_page_and_rotator( $post_types ) {
     return array( 'page', 'rotator','post' );
}
add_action( 'be_gallery_metabox_post_types', 'be_gallery_metabox_page_and_rotator' );
 
* Chỉ định hiển thị gallery images metabox ở một số page/post.
Thêm vào theme functions.php
<?php
 
/**
* Limit Gallery Metabox to Specific Page
* @author Bill Erickson
* @link http://www.wordpress.org/extend/plugins/gallery-metabox
* @since 1.0
*
* @param bool display metabox
* @param string post ID
* @return bool display metabox
*/
function be_gallery_metabox_on_specific_page(  $true, $post_id ) {
     return '10' == $post_id;
}
 
add_filter( 'be_gallery_metabox_limit', 'be_gallery_metabox_on_specific_page', 10, 2 );
 
Giới hạn hiển thị tính năng tạo gallery ảnh cho một số dữ liệu post type.
 
* Tùy biến wp_query:
Bạn có thể chỉ định những image được sử dụng nếu có custom field thỏa mãn điều kiện.  Bằng cách sửa lại tham số trước khi lấy dữ liệu bởi WP_Query.
<?php
 
add_filter( 'be_gallery_metabox_args', 'be_gallery_custom_args' );
/**
* Only show images marked as Include in Rotator
* @author Bill Erickson
* @link http://www.wordpress.org/extend/plugins/gallery-metabox
* @since 1.0
*
* @param array query $args
* @return array query $args
*/
function be_gallery_custom_args( $args ) {
     $args['meta_query'] = array(
          array(
               'key' => 'be_rotator_include',
               'value' => '1'
          )
     );
     return $args;
}
 
Ví dụ khác Nếu muốn ảnh đươc được xắp xếp theo tiêu đề AlphaB.
<?php
 
/**
* Gallery Metabox - sort by title
* @author Bill Erickson
* @link http://www.wordpress.org/extend/plugins/gallery-metabox
* @since 1.0
*
* @param array query $args
* @return array query $args
*/
function be_gallery_custom_args( $args ) {
     $args['orderby'] = 'title';
     $args['order'] = 'ASC';
     return $args;
}
add_filter( 'be_gallery_metabox_args', 'be_gallery_custom_args' );
 
* Xóa hình dấu X ở mỗi ảnh, dùng để xóa gallery image.
add_filter( 'be_gallery_metabox_remove', '__return_false' );
 
Made with help of Dr.Explain

Unregistered version