Last active
October 14, 2015 04:13
-
-
Save partageit/0386090a338c779fa0c3 to your computer and use it in GitHub Desktop.
Partage-it.com : changer l'apparence des galeries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Custom gallery output */ | |
function customGalleryOutput($output = "", $attr) { | |
// This part is globally copied from the WordPress gallery function | |
$return = $output; // fallback | |
$post = get_post(); | |
if ( ! empty( $attr['ids'] ) ) { | |
// 'ids' is explicitly ordered, unless you specify otherwise. | |
if ( empty( $attr['orderby'] ) ) | |
$attr['orderby'] = 'post__in'; | |
$attr['include'] = $attr['ids']; | |
} | |
// We're trusting author input, so let's at least make sure it looks like a valid orderby statement | |
if ( isset( $attr['orderby'] ) ) { | |
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); | |
if ( !$attr['orderby'] ) | |
unset( $attr['orderby'] ); | |
} | |
extract(shortcode_atts(array( | |
'order' => 'ASC', | |
'orderby' => 'menu_order ID', | |
'id' => $post ? $post->ID : 0, | |
//'itemtag' => $html5 ? 'figure' : 'dl', | |
//'icontag' => $html5 ? 'div' : 'dt', | |
//'captiontag' => $html5 ? 'figcaption' : 'dd', | |
//'columns' => 3, | |
'size' => 'thumbnail', | |
'include' => '', | |
'exclude' => '', | |
//'link' => '', | |
// This parameter is added to keep the default behaviour: | |
'usedefault' => 0 | |
), $attr, 'gallery')); | |
if ($usedefault) return $output; | |
$id = intval($id); | |
if ( 'RAND' == $order ) | |
$orderby = 'none'; | |
if ( !empty($include) ) { | |
$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); | |
$attachments = array(); | |
foreach ( $_attachments as $key => $val ) { | |
$attachments[$val->ID] = $_attachments[$key]; | |
} | |
} elseif ( !empty($exclude) ) { | |
$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); | |
} else { | |
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); | |
} | |
if (empty($attachments)) | |
return ''; | |
// This is the part to customize. Here we use Twitter Bootstrap to display images. | |
$return = '<div class="row">'; | |
foreach ($attachments as $attachment) { | |
$return .= '<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">'; | |
$return .= wp_get_attachment_image($attachment->ID, $size); | |
$return .= '</div>'; | |
} | |
$return .= '</div>'; | |
$return .= '<div class="clearfix"></div>'; | |
return $return; | |
} | |
add_filter("post_gallery", "customGalleryOutput", 10, 4); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment