Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

jake

By: a guest on Apr 25th, 2010  |  syntax: None  |  size: 0.94 KB  |  views: 134  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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'); }