doumo2501 2014-04-30 04:17
浏览 16
已采纳

如何在wordpress中“动态”更改图像的大小

I am working on a custom Wordpress Site and I need to be able to output the image being assigned to the post as the "Featured Image" So, here is my PHP code

$theimage=wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID(), array( 160,260 ), false, '' ), 'product-image2');    
$product_shortcode .= '<li>';
$product_shortcode .= '<a href="' . get_permalink() . '"><h4>'. get_the_title().'</h4>';
$product_shortcode .= '<img src="'.$theimage[0].'" alt="" /> ';
$product_shortcode .= '</a>';
$product_shortcode .= '</li>';

And now here is my problem enter image description here The image is being displayed in (160 x 140) As you can see. I need the image to be displayed wholly. When I inspected it the image src in output was ../~image-path/feed160x140.png. Which is the thumbnail size generated by wordpress. If it displayed the normal ../~image-path/feed.png I would be fine.

In my code, and according to the Wordpress Reference Website the array(160X260) should display it in those dimensions. Not happening for me.

I need help from the WP Gurus.

  • 写回答

2条回答 默认 最新

  • douzhuoxia0587 2014-04-30 05:57
    关注

    Try this, I hope this is working for you.

    $theimage=wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()),'full');    
    $product_shortcode .= '<li>';
    $product_shortcode .= '<a href="' . get_permalink() . '"><h4>'. get_the_title().'</h4>';
    $product_shortcode .= '<img class="img-responsive" src="'.$theimage[0].'" alt="" /> ';
    $product_shortcode .= '</a>';
    
    $product_shortcode .= '</li>';
    

    Used img-responsive this class directly if you used bootstrap 3 other wise write css like.

    .img-responsive{
      height: 180px;
      width: 100%;
      display: block;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧