I'm working on a theme with a side scrolling image slideshow. I'm trying to set the container width dynamically. I'm trying to grab the image widths of all the images in the post/page and add them up with their padding.
I'm able to get the original attachment width with:
$attachment_width = wp_get_attachment_metadata($attachment_id);
echo $attachment_width['width'];
But wp_get_attachment_metadata does not seem to return the width for the medium size of the images.
I tried also to use the php function getimagesize to get the image widths, but I get errors with this code:
$attachment_width = wp_get_attachment_image_src($attachment_id, $size='medium');
list($width, $height, $type, $attr) = getimagesize($attachment_width);
echo $width;
For clarity, here is the full code I'm using for scrolling image slideshow from the functions.php:
// Add lightbox rel
function wp_get_attachment_link_canoe($id = 0, $size = 'thumbnail', $permalink = false, $icon = false) {
$_post = & get_post( intval($id) );
if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
return __('Missing Attachment');
if ( $permalink )
$url = get_attachment_link($_post->ID);
$post_title = attribute_escape($_post->post_title);
$link_text = wp_get_attachment_image($id, $size, $icon);
if ( !$link_text )
$link_text = $_post->post_title;
return "<a rel='lightbox[$_post->post_parent]' href='$url' title='$post_title'>$link_text</a>";
}
// Scroll shortcode
function scroll(){
echo '<div class="scroll">';
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'order_by' => 'menu_order ID') );
foreach ( $attachments as $attachment_id => $attachment ) {
?><?php echo wp_get_attachment_link_canoe($attachment_id,$size='medium'); ?><?php
/*
$attachment_width = wp_get_attachment_metadata($attachment_id);
echo $attachment_width['width'];
$attachment_width = wp_get_attachment_image_src($attachment_id, $size='medium');
list($width, $height, $type, $attr) = getimagesize($attachment_width);
echo $width;
*/
}
echo '</div>';
}
add_shortcode('scroll','scroll');
I want to set the width of the class "scroll". Temporarily I've set it statically very large. But this inhibits the usability of the side scroll.