开发者

Wordpress image attachment

开发者 https://www.devze.com 2023-03-14 18:27 出处:网络
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开发者_C百科 size with \"the_attachment_li

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开发者_C百科 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);
}
}   


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消