doucong3048 2016-11-18 21:29
浏览 49

WP add_image_size绑定到不同的帖子类型

I have maked site on WP. There are two slider-bars and some sections with img. Resolutions of this img are different.

I want ( need ) to use add_image_size function to crop image for my tasks, but how I can bind func. add_image_size with imgs for one of the sections / slide-bars? I don't understand, how i must declare that thumbnail for post (for ex.) must be cropped by add_image_size. Sorry, may be for this is stupid question

  • 写回答

1条回答 默认 最新

  • dongtou9934 2016-11-19 01:35
    关注

    Usually you will declare a new image size in your functions.php, something like:

    add_image_size( '1280-thumb', 1280 );//1280px wide, free high
    

    and then call that image size wherever you need it. So what you need to do is create as many image sizes as you need and then call each specific size in each sidebar or anywhere else on your site where those images might be needed. You could limit when these thumbnails are created based on the post type they are uploaded to for example with something like this:

    if( get_post_type() == ‘your_post_type’ ) {
        add_image_size( '1280-thumb', 1280 );//1280px wide, free high
    }
    

    This will only create the ‘1280-thumb’ for images uploaded directly to posts belonging to a custom post type named ‘your_custom_post_type’.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?