Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $caption_image_count = 0;
- function count_images(){
- global $post;
- $thePostID = $post->ID;
- $parameters = array(
- 'post_type' => 'attachment',
- 'post_parent' => $thePostID,
- 'post_mime_type' => 'image');
- $attachments = get_children($parameters);
- $content = count($attachments);
- return $content;
- }
- #add_filter('the_content','count_images');
- function caption_image_callback($matches) {
- global $caption_image_count;
- $caption_image_count += 1;
- $c = count_images();
- for ($i=1; $i <= $c; $i++) {
- if (is_single()) {
- return '<div class="inum"><span align="center">' . $caption_image_count . '</span></div><div align="left">
- <img src="'.$matches[2].'"'.$matches[3].'></div>';
- } else {
- return '<img src="'.$matches[2].'"'.$matches[3].'>';
- }
- }
- }
- function caption_image($post_body_content) {
- global $caption_image_count;
- $post_body_content = preg_replace_callback("|<img(.*?)src=\"(.*?)\"(.*?)>|","caption_image_callback",$post_body_content);
- $caption_image_count = 0;
- return $post_body_content;
- }
- if ( current_user_can('edit_plugins') ) {
- add_filter('the_content', 'caption_image'); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement