【问题标题】:php mysql - get product thumbnail image of a productphp mysql - 获取产品的产品缩略图
【发布时间】:2018-04-28 05:34:49
【问题描述】:

我正在使用 woocommerce,我正在尝试检索产品的缩略图,我尝试使用 woocommerce api 但它没有任何缩略图参数,我在数据库中搜索并在 wp_postmeta 中找到它table,但是meta_value的结构很难看懂,例如:

a:5:{s:5:"width";i:694;s:6:"height";i:660;s:4:"file";s:69:"2017/11/روغن-ذرت-زرین-1.8-لیتری-33150-26500اصل.jpg";s:5:"sizes";a:4:{s:9:"thumbnail";a:4:{s:4:"file";s:69:"روغن-ذرت-زرین-1.8-لیتری-33150-26500اصل-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:69:"روغن-ذرت-زرین-1.8-لیتری-33150-26500اصل-300x285.jpg";s:5:"width";i:300;s:6:"height";i:285;s:9:"mime-type";s:10:"image/jpeg";}s:14:"shop_thumbnail";a:4:{s:4:"file";s:69:"روغن-ذرت-زرین-1.8-لیتری-33150-26500اصل-150x143.jpg";s:5:"width";i:150;s:6:"height";i:143;s:9:"mime-type";s:10:"image/jpeg";}s:12:"shop_catalog";a:4:{s:4:"file";s:69:"روغن-ذرت-زرین-1.8-لیتری-33150-26500اصل-300x285.jpg";s:5:"width";i:300;s:6:"height";i:285;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"1";s:8:"keywords";a:0:{}}}

它包含不同尺寸的产品的所有图像,问题是,我如何在 php 中读取它并从中获取我想要的图像 src?

【问题讨论】:

  • 在您要检索缩略图的 wichi 页面上

标签: php mysql wordpress woocommerce


【解决方案1】:

该格式是序列化数组,你可以使用WordPress函数maybe_unserialize反序列化它

maybe_unserialize( $your_meta_value );

【讨论】:

  • 感谢回复,我没有包含任何wordpress类,如何导入我需要访问此功能的类?
  • 欢迎您,您只需在该函数中传递meta_value,如果您需要更多详细信息,请告诉我。
【解决方案2】:

只是对@Aiyaz 的回答发表评论, 要包含 wordpress 功能,只需使用 require_once("wordpress-folder-path/wp-load.php"); 其中 wordpress-folder-path 是您的 wordpress 安装路径。

但是您可能会使用 php 的原生 unserialize($data) 函数而侥幸。

【讨论】:

    猜你喜欢
    • 2014-07-26
    • 2017-05-24
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 2019-01-07
    相关资源
    最近更新 更多