View difference between Paste ID: sFe6dhqL and
SHOW:
|
|
- or go back to the newest paste.
| 1 | - | |
| 1 | + | $caption_image_count = 0; |
| 2 | ||
| 3 | function count_images(){
| |
| 4 | global $post; | |
| 5 | $thePostID = $post->ID; | |
| 6 | $parameters = array( | |
| 7 | 'post_type' => 'attachment', | |
| 8 | 'post_parent' => $thePostID, | |
| 9 | 'post_mime_type' => 'image'); | |
| 10 | $attachments = get_children($parameters); | |
| 11 | $content = count($attachments); | |
| 12 | return $content; | |
| 13 | } | |
| 14 | #add_filter('the_content','count_images');
| |
| 15 | ||
| 16 | function caption_image_callback($matches) {
| |
| 17 | global $caption_image_count; | |
| 18 | $caption_image_count += 1; | |
| 19 | $c = count_images(); | |
| 20 | for ($i=1; $i <= $c; $i++) {
| |
| 21 | if (is_single()) {
| |
| 22 | return '<div class="inum"><span align="center">' . $caption_image_count . '</span></div><div align="left"> | |
| 23 | <img src="'.$matches[2].'"'.$matches[3].'></div>'; | |
| 24 | } else {
| |
| 25 | return '<img src="'.$matches[2].'"'.$matches[3].'>'; | |
| 26 | } | |
| 27 | } | |
| 28 | } | |
| 29 | ||
| 30 | function caption_image($post_body_content) {
| |
| 31 | global $caption_image_count; | |
| 32 | $post_body_content = preg_replace_callback("|<img(.*?)src=\"(.*?)\"(.*?)>|","caption_image_callback",$post_body_content);
| |
| 33 | $caption_image_count = 0; | |
| 34 | return $post_body_content; | |
| 35 | } | |
| 36 | ||
| 37 | if ( current_user_can('edit_plugins') ) {
| |
| 38 | add_filter('the_content', 'caption_image'); } |