• Resolved jtrollia

    (@malivuk)


    Hi,

    I’m trying to use this function to get thumbnails height and width but it doesn’t work.

    How could I get dynamically the attachment_id parameter ?

    Thumbnails values are visible in the code… maybe is there an easier way to get them ?

    Thanks for any tips.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Where are you trying to use this (template file)? What theme are you using? Can you show us the code that isn’t working.

    Thread Starter jtrollia

    (@malivuk)

    I’m trying to use this in the loop (index). I’m using gridly.

    I was trying codex first example :

    <?php
    $attachment_id = 8; // attachment ID
    $image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
    ?>
    <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">

    Without success since I can’t get the attchment_id… So it doesn’t return anything 🙁

    Moderator keesiemeijer

    (@keesiemeijer)

    What is it exacly you want to do and on what page or template file? Get the first attachment of a post?

    Thread Starter jtrollia

    (@malivuk)

    I want to get the dimension of the posts thumbnails displayed on index page.

    So I plan to use get_attachment_image_src function. In order to do so, I need to know the thumbnail id (“attchment_id” in the code).

    Moderator keesiemeijer

    (@keesiemeijer)

    Ah, it’s a post thumbnail.
    Try it with get_post_thumbnail_id():
    http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id

    // inside the loop
    $id = get_post_thumbnail_id( $post->ID );
    
    $image = wp_get_attachment_image_src( $id, 'summary-image' );
    
    $width = $image[1];
    $height = $image[2];

    Thread Starter jtrollia

    (@malivuk)

    That’s exactly what I needed… Thanks a lot !

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. I’m glad you’ve got it resolved 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Get image / thumbnail dimensions’ is closed to new replies.