
jake
By: a guest on
Apr 25th, 2010 | syntax:
None | size: 0.94 KB | hits: 129 | expires: Never
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) {
$c = count_images();
for ($i=1; $i <= $c; $i++) {
if (is_single()) {
return '<div class="inum"><span align="center">'.$i.'</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) {
$post_body_content = preg_replace_callback("|<img(.*?)src=\"(.*?)\"(.*?)>|","caption_image_callback",$post_body_content);
return $post_body_content;
}
if ( current_user_can('edit_plugins') ) {
add_filter('the_content', 'caption_image'); }