WordPress.org

Ready to get started?Download WordPress

Forums

Attachments
[resolved] Getting width & height in new Attachments (3 posts)

  1. indextwo
    Member
    Posted 1 year ago #

    I have been using Attachments for years as a great and very, very handy plugin.

    However I just updated it (from proably a reasonably old version) on a client's site and, although I've updated the templates to pull out the Attachments info using the new OOP methods, I cannot, for the life of me, get the width and height information for each image.

    I do need to explicitly get the width & height, as these are then being echoed to a jQuery function for zooming, and it doesn't function correctly without them.

    Any help would be greatly appreciated.

    http://wordpress.org/extend/plugins/attachments/

  2. indextwo
    Member
    Posted 1 year ago #

    In answer to my own question:

    $attachments = new Attachments('attachments');
    
    if($attachments->exist()) :
    	while( $attachments->get() ) : 
    
    		$imgID = $attachments->id();
    		$image = wp_get_attachment_image_src($imgID, 'full');
    
    		if ($attachments->field( 'title' ) == 'unzoomed') {
    			$smallImage = $image[0];
    		}
    
    		if ($attachments->field( 'title' ) == 'zoomed') {
    			$zoomImage = $image[0];
    			$zoomWidth = $image[1];
    			$zoomHeight = $image[2];
    		}
    
    	endwhile;
    endif;

    The secret was to use WP's default wp_get_attachment_image_src() based on the attachment ID, which returns a standard array.

  3. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Glad you got it resolved, I'll be sure to add utility methods to get dimensions because I think that'd be useful.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic