Created
January 28, 2014 11:33
-
-
Save lohic/8666132 to your computer and use it in GitHub Desktop.
Un autre script pour gallery 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://shibashake.com/wordpress-theme/how-to-render-your-own-wordpress-photo-gallery | |
function parse_gallery_shortcode($atts) { | |
global $post; | |
if ( ! empty( $atts['ids'] ) ) { | |
// 'ids' is explicitly ordered, unless you specify otherwise. | |
if ( empty( $atts['orderby'] ) ) | |
$atts['orderby'] = 'post__in'; | |
$atts['include'] = $atts['ids']; | |
} | |
extract(shortcode_atts(array( | |
'orderby' => 'menu_order ASC, ID ASC', | |
'include' => '', | |
'id' => $post->ID, | |
'itemtag' => 'dl', | |
'icontag' => 'dt', | |
'captiontag' => 'dd', | |
'columns' => 3, | |
'size' => 'medium', | |
'link' => 'file' | |
), $atts)); | |
$args = array( | |
'post_type' => 'attachment', | |
'post_status' => 'inherit', | |
'post_mime_type' => 'image', | |
'orderby' => $orderby | |
); | |
if ( !empty($include) ) | |
$args['include'] = $include; | |
else { | |
$args['post_parent'] = $id; | |
$args['numberposts'] = -1; | |
} | |
$images = get_posts($args); | |
foreach ( $images as $image ) { | |
$caption = $image->post_excerpt; | |
$description = $image->post_content; | |
if($description == '') $description = $image->post_title; | |
$image_alt = get_post_meta($image->ID,'_wp_attachment_image_alt', true); | |
// render your gallery here | |
echo wp_get_attachment_image($image->ID, $size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment