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

  1. indextwo
    Posted 3 years 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.


  2. indextwo
    Posted 3 years 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];

    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
    Plugin Author

    Posted 3 years 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

  • Attachments
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic