View difference between Paste ID: n1mfN3NX and E3p4RETm
SHOW: | | - or go back to the newest paste.
1
remove_shortcode('gallery','gallery_shortcode');
2
add_shortcode('gallery','custom_gallery_shortcode');
3
4
function custom_gallery_shortcode( $attr ) {
5
/**
6
 * The 'custom' Gallery shortcode.
7
 *
8
 * based on the code from  /wp-includes/media.php line 745 in version wp3.2
9
 */
10
	global $post;
11
12
	static $instance = 0;
13
	$instance++;
14
	
15
	// Allow plugins/themes to override the default gallery template.
16
	$output = apply_filters('post_gallery', '', $attr);
17
	if ( $output != '' )
18
		return $output;
19
20
	// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
21
	if ( isset( $attr['orderby'] ) ) {
22
		$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
23
		if ( !$attr['orderby'] )
24
			unset( $attr['orderby'] );
25
	}
26
27
	extract(shortcode_atts(array(
28
		'order'      => 'ASC',
29
		'orderby'    => 'menu_order ID',
30
		'id'         => $post->ID,
31
		'itemtag'    => 'dl',
32
		'icontag'    => 'dt',
33
		'captiontag' => 'dd',
34
		'columns'    => 3,
35
		'size'       => 'thumbnail',
36
		'include'    => '',
37
		'exclude'    => ''
38
	), $attr));
39
40
	$id = intval($id);
41
	if ( 'RAND' == $order )
42
		$orderby = 'none';
43
44
	if ( !empty($include) ) {
45
		$include = preg_replace( '/[^0-9,]+/', '', $include );
46
		$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
47
48
		$attachments = array();
49
		foreach ( $_attachments as $key => $val ) {
50
			$attachments[$val->ID] = $_attachments[$key];
51
		}
52
	} elseif ( !empty($exclude) ) {
53
		$exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
54
		$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
55
	} else {
56
		$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
57
	}
58
59
	if ( empty($attachments) )
60
		return '';
61
62
	if ( is_feed() ) {
63
		$output = "\n";
64
		foreach ( $attachments as $att_id => $attachment )
65
			$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
66
		return $output;
67
	}
68
69
	$itemtag = tag_escape($itemtag);
70
	$captiontag = tag_escape($captiontag);
71
	$columns = intval($columns);
72
	$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
73
	$float = is_rtl() ? 'right' : 'left';
74
75
	$selector = "gallery-{$instance}";
76
77
	$gallery_style = $gallery_div = '';
78
	if ( apply_filters( 'use_default_gallery_style', true ) )
79
		$gallery_style = "
80
		<style type='text/css'>
81
			#{$selector} {
82
				margin: auto;
83
			}
84
			#{$selector} .gallery-item {
85
				float: {$float};
86
				margin-top: 10px;
87
				text-align: center;
88
				width: {$itemwidth}%;
89
			}
90
			#{$selector} img {
91
				border: 2px solid #cfcfcf;
92
			}
93
			#{$selector} .gallery-caption {
94
				margin-left: 0;
95
			}
96
		</style>
97
		<!-- see gallery_shortcode() in wp-includes/media.php -->";
98
	$size_class = sanitize_html_class( $size );
99
	$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
100
	$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
101
102
	$i = 0;
103
	foreach ( $attachments as $id => $attachment ) {
104
		$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
105
106
		$output .= "<{$itemtag} class='gallery-item'>";
107
		
108-
 $output .= "<span class='gallery-item-counter'>".($i+1)."</span>"; //NEW
108+
 $output .= "<div class='imageNum'><span>".($i+1)."</span></div>"; //NEW
109
 
110
		$output .= "
111
			<{$icontag} class='gallery-icon'>
112
				$link
113
			</{$icontag}>";
114
		if ( $captiontag && trim($attachment->post_excerpt) ) {
115
			$output .= "
116
				<{$captiontag} class='wp-caption-text gallery-caption'>
117
				" . wptexturize($attachment->post_excerpt) . "
118
				</{$captiontag}>";
119
		}
120
		$output .= "</{$itemtag}>";
121
		if ( $columns > 0 && ++$i % $columns == 0 )
122
			$output .= '<br style="clear: both" />';
123
	}
124
125
	$output .= "
126
			<br style='clear: both;' />
127
		</div>\n";
128
129
	return $output;
130
}