Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

On the front-end, I'm using a query to show all attachments attached to the current post. However, on the compose page, there's no way for a user to see how many images are attached without opening up the media gallery.

I would like to add a meta box (or something) to display the current number of attached images – perhaps something like this: http://cl.ly/image/0a2q171v3y2u

Is this possible?

Thanks!

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted
add_action( 'add_meta_boxes', 'attached_images_meta' );

function attached_images_meta() {
    $screens = array( 'post', 'page' ); //add more in here as you see fit
    foreach ($screens as $screen) {
        add_meta_box(
            'attached_images_meta_box', //this is the id of the box
            'Attached Images', //this is the title
            'attached_images_meta_box', //the callback
            $screen, //the post type
            'side' //the placement
        );
    }
}
function attached_images_meta_box($post){
    $args = array('post_type'=>'attachment','post_parent'=>$post->ID);
    $count = count(get_children($args));
    echo '<a href="#" class="button insert-media add_media" data-editor="content">'.$count.' Images</a>';
}

The above will link to the media uploader. I added the link because the screenshot you posted looked like a link. Feel free to remove the link like so:

echo $count.' Images';

Just pop this in your functions.php, custom plugin, etc.

share|improve this answer
    
Perfect, thanks Josh! –  mattisahuman Feb 17 '13 at 1:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.