Need help with wordpress code

Discussion in 'Programming' started by hasibrsohel, Dec 9, 2013.

  1. #1
    Hi,

    Can anyone please help me to display image properties (like- image type png/jpg, image size, image weight etc) for wordpress.

    In details:
    User will upload an image in wordpress (from backend) post using featured image area and wordpress post page (front end) will display the image size, image type, image weight etc.

    Thanks!
     
    hasibrsohel, Dec 9, 2013 IP
  2. A_H

    A_H Greenhorn

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    Try this code:
    function my_display_featured_image(){global $post;
    $thumbnail_id = get_post_thumbnail_id($post->ID);
    $thumbnail_details = get_posts(array('p'=> $thumbnail_id,'post_type'=>'attachment'));
    $thumbnail_src = wp_get_attachment_image_src( $thumbnail_id,'full');
    $thumbnail_width = $thumbnail_src[1];
    if($thumbnail_src && isset($thumbnail_src[0])){
    echo '<div class="featured-image';if(!empty( $thumbnail_details[0]->post_excerpt )) echo ' wp-caption';
    echo '" style="max-width: '. $thumbnail_width .'px;">';if(!empty( $thumbnail_details[0]->post_excerpt )){
    echo '<p class="featured-image-caption">';
    echo $thumbnail_details[0]->post_excerpt;
    echo '</p>';}
    the_post_thumbnail( $post->ID );
    echo '</div>';}}
    PHP:
     
    A_H, Dec 9, 2013 IP
  3. hasibrsohel

    hasibrsohel Member

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Thanks for sharing the code. I will try and inform you the update.
    Thanks again!
     
    hasibrsohel, Dec 9, 2013 IP
  4. vinayupadhyay9

    vinayupadhyay9 Active Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #4
    Hi you can use
    <ul>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();

    $args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => $post->ID
    );

    $attachments = get_posts( $args );
    if ( $attachments ) {
    foreach ( $attachments as $attachment ) {
    echo '<li>';
    echo wp_get_attachment_image( $attachment->ID, 'full' );
    echo '<p>';
    echo apply_filters( 'the_title', $attachment->post_title );
    echo '</p></li>';
    }
    }

    endwhile; endif; ?>
    </ul>
     
    vinayupadhyay9, Dec 9, 2013 IP
  5. hasibrsohel

    hasibrsohel Member

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    I have tried above code but its not working for me. Not sure whay :(
     
    hasibrsohel, May 14, 2014 IP
  6. msx

    msx Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #6
    Use this function http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id , it will return array containing ID, title..etc, there is example on that page. This works for featured images (as you explained)
     
    msx, May 15, 2014 IP