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