Last active
January 4, 2016 19:19
-
-
Save lohic/8666152 to your computer and use it in GitHub Desktop.
3 script gallerie wordpress
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 | |
// cf http://tiffanybbrown.com/2013/02/03/wordpress-adding-custom-galleries-to-your-theme/ | |
remove_shortcode('gallery', 'gallery_shortcode'); | |
add_shortcode('gallery', 'custom_gallery'); | |
function custom_gallery($attr) { | |
$post = get_post(); | |
static $instance = 0; | |
$instance++; | |
# hard-coding these values so that they can't be broken | |
$attr['columns'] = 1; | |
$attr['size'] = 'full'; | |
$attr['link'] = 'none'; | |
$attr['orderby'] = 'post__in'; | |
$attr['include'] = $attr['ids']; | |
#Allow plugins/themes to override the default gallery template. | |
$output = apply_filters('post_gallery', '', $attr); | |
if ( $output != '' ) | |
return $output; | |
# 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->ID, | |
'itemtag' => 'div', | |
'icontag' => 'div', | |
'captiontag' => 'p', | |
'columns' => 1, | |
'size' => 'thumbnail', | |
'include' => '', | |
'exclude' => '' | |
), $attr)); | |
$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 ''; | |
$gallery_style = $gallery_div = ''; | |
if ( apply_filters( 'use_default_gallery_style', true ) ) | |
$gallery_style = "<!-- see gallery_shortcode() in functions.php -->"; | |
$gallery_div = "<div id='homepage-gallery-wrap' class='gallery gallery-columns-1 gallery-size-full'>"; | |
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div ); | |
foreach ( $attachments as $id => $attachment ) { | |
$link = wp_get_attachment_link($id, 'full', true, false); | |
$output .= "<div class='homepage-gallery-item'>"; | |
$output .= " | |
<div class='homepage-gallery-icon'> | |
$link | |
</div>"; | |
if ( $captiontag && trim($attachment->post_excerpt) ) { | |
$output .= " | |
<p class='wp-caption-text homepage-gallery-caption'> | |
" . wptexturize($attachment->post_excerpt) . " | |
</p>"; | |
} | |
$output .= "</div>"; | |
} | |
$output .= "</div>\n"; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Celui-ci fonctionne bien !