douyujun0152
2012-10-23 00:50 阅读 76
已采纳

删除wp_get_attachment_image图像大小

Is there any way to remove the image size of the wp_get_attachment function?

I was trying the following code with no luck, trying to get it either 100% or nothing at all.

echo wp_get_attachment_image($variable, array(100 . '%', 100 . '%'));

EDIT

This is what I ended up with that works perfectly thanks to drew010.

echo '<img src="'.wp_get_attachment_url($variable).'" alt="'.get_the_title().'" />';
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    dragon5006 dragon5006 2012-10-23 01:05

    @Jrod has the correct answer IMO, but you can also just call

    wp_get_attachment_url($variable);
    

    which gives you the URL to the full image. Then you can simply construct your own HTML markup for displaying the image.

    点赞 1 评论 复制链接分享
  • douchu2823 douchu2823 2012-10-23 01:00

    If you want the full size image you should use the following:

    echo wp_get_attachment_image($variable, 'full');

    点赞 5 评论 复制链接分享
  • duanluangua8850 duanluangua8850 2012-11-20 13:00

    You can't use it this way: alt="'.get_the_title().'"

    You must use esc_attr($attachment->post_title) or the_title_attribute().

    If the title has some html tags your alt attribute can crash your html outline. Trust me, a year ago I searched for over 1 hour this bug in some theme.

    点赞 评论 复制链接分享

相关推荐