WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] adding classes to tall and wide images (3 posts)

  1. nrrghh
    Member
    Posted 4 years ago #

    is this possible via the admin system?

    ie can I programically check width of image file and thus apply a class?

    m

  2. nrrghh
    Member
    Posted 4 years ago #

    hi

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

    indicates that can get at image width

    not being any kind of php expert

    how do I get at the width value

    so I can then test and add a class

    thanks in advance

    m

  3. nrrghh
    Member
    Posted 4 years ago #

    hi

    have figured it

    this by the way is so I can have a grid of floated li's containing thumbnails & style based on image width

    in the themes function.php (well if you are hacking out from Sandbox)

    there is a chunk of code to style the Gallery

    find

    $img_src = wp_get_attachment_image_src( $id, $size );

    you can then grab the width
    $img_width = $img_src[1]; // added for for width test

    which you need to do before
    $img_src = $img_src[0];

    then in the output code

    if ( $img_width == 150 ) { $output .= ' class="wide" '; } // test for grid width styling

    enjoy

    m

Topic Closed

This topic has been closed to new replies.

About this Topic