Support more than one gallery on the same page, props jamescollins, fixes #7678

git-svn-id: http://svn.automattic.com/wordpress/trunk@11339 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-05-15 08:52:04 +00:00
parent 378aaa973e
commit 8fcacb951d
1 changed files with 12 additions and 7 deletions

View File

@ -610,6 +610,9 @@ add_shortcode('gallery', 'gallery_shortcode');
*/ */
function gallery_shortcode($attr) { function gallery_shortcode($attr) {
global $post; global $post;
static $instance = 0;
$instance++;
// Allow plugins/themes to override the default gallery template. // Allow plugins/themes to override the default gallery template.
$output = apply_filters('post_gallery', '', $attr); $output = apply_filters('post_gallery', '', $attr);
@ -642,8 +645,8 @@ function gallery_shortcode($attr) {
if ( is_feed() ) { if ( is_feed() ) {
$output = "\n"; $output = "\n";
foreach ( $attachments as $id => $attachment ) foreach ( $attachments as $att_id => $attachment )
$output .= wp_get_attachment_link($id, $size, true) . "\n"; $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
return $output; return $output;
} }
@ -651,26 +654,28 @@ function gallery_shortcode($attr) {
$captiontag = tag_escape($captiontag); $captiontag = tag_escape($captiontag);
$columns = intval($columns); $columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100; $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$selector = "gallery-{$instance}";
$output = apply_filters('gallery_style', " $output = apply_filters('gallery_style', "
<style type='text/css'> <style type='text/css'>
.gallery { #{$selector} {
margin: auto; margin: auto;
} }
.gallery-item { #{$selector} .gallery-item {
float: left; float: left;
margin-top: 10px; margin-top: 10px;
text-align: center; text-align: center;
width: {$itemwidth}%; } width: {$itemwidth}%; }
.gallery img { #{$selector} img {
border: 2px solid #cfcfcf; border: 2px solid #cfcfcf;
} }
.gallery-caption { #{$selector} .gallery-caption {
margin-left: 0; margin-left: 0;
} }
</style> </style>
<!-- see gallery_shortcode() in wp-includes/media.php --> <!-- see gallery_shortcode() in wp-includes/media.php -->
<div class='gallery'>"); <div id='$selector' class='gallery galleryid-{$id}'>");
$i = 0; $i = 0;
foreach ( $attachments as $id => $attachment ) { foreach ( $attachments as $id => $attachment ) {