WordPress image attachment

I am using this code to get all posts attachment which it is doing fine.
My problem is I am not getting the desired attachment size. When I don’t specify the size with “the_attachment_link($attachment->ID);” I get the thumbnail and when I try by adding “medium, small, large, or full” I get the full size only.
Am I missing something here? I need some support please.

    $args = array(
        'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $post->ID
); 
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
    echo apply_filters('the_title', $attachment->post_title);
    the_attachment_link($attachment->ID, 'medium', true);
}
}   

Related posts

Leave a Reply

1 comment

  1. Hi try something like this:

    query_posts( array('post_type' => 'attachment','numberposts' => null,'post_status' => null,'post_parent' => $post->ID));
        <?php if (have_posts()) : while (have_posts()) :the_post(); 
                $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
        ?>
            <img src="<?php echo $src[0]; ?>" width="174px" height="142px" alt="" />                                
        <?php       
        endwhile; 
        else :          
            echo '<h3>Oops, something went wrong.</h3>';
        endif;
        wp_reset_query();
        ?>                      
        } ?>
    

    make use of the $src[0].
    set the height and width according to your preference.

    hope this solves it.