首页 > 解决方案 > 如何使用 Timber/Twig 从 ACF 选项页面图像中显示缩略图

问题描述

我正在开发一个自定义 WordPress 主题,并且很难从 ACF(高级自定义字段)选项页面字段中将缩略图图像显示在我的页面上,我在 WordPress 中使用了木材/树枝,并尝试了多种方法但均未成功:

{{options.tool_agreement.url }}并且{{options.tool_agreement('thumbnail') }}还有{{options.tool_agreement.thumbnail }}而且{{options.tool_agreement('thumbnail').url }}这些都不适合我??

〜感谢任何提示!

这是转储的示例:{{dump(options.tool_agreement)}}

array (size=24)
  'ID' => int 254
  'id' => int 254
  'title' => string 'sample-agreement' (length=16)
  'filename' => string 'sample-agreement.jpg' (length=20)
  'filesize' => int 54741
  'url' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement.jpg' (length=78)
  'link' => string 'https://protoolsite.local/sample-agreement/' (length=48)
  'alt' => string '' (length=0)
  'author' => string '1' (length=1)
  'description' => string '' (length=0)
  'caption' => string '' (length=0)
  'name' => string 'sample-agreement' (length=16)
  'status' => string 'inherit' (length=7)
  'uploaded_to' => int 0
  'date' => string '2021-07-02 00:27:42' (length=19)
  'modified' => string '2021-07-02 00:27:42' (length=19)
  'menu_order' => int 0
  'mime_type' => string 'image/jpeg' (length=10)
  'type' => string 'image' (length=5)
  'subtype' => string 'jpeg' (length=4)
  'icon' => string 'https://protoolsite.local/wp-includes/images/media/default.png' (length=67)
  'width' => int 544
  'height' => int 703
  'sizes' => 
    array (size=18)
      'thumbnail' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement-150x150.jpg' (length=86)
      'thumbnail-width' => int 150
      'thumbnail-height' => int 150
      'medium' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement-232x300.jpg' (length=86)
      'medium-width' => int 232
      'medium-height' => int 300
      'medium_large' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement.jpg' (length=78)
      'medium_large-width' => int 544
      'medium_large-height' => int 703
      'large' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement.jpg' (length=78)
      'large-width' => int 544
      'large-height' => int 703
      '1536x1536' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement.jpg' (length=78)
      '1536x1536-width' => int 544
      '1536x1536-height' => int 703
      '2048x2048' => string 'https://protoolsite.local/wp-content/uploads/2021/07/sample-agreement.jpg' (length=78)
      '2048x2048-width' => int 544
      '2048x2048-height' => int 703

标签: wordpresstwigcustom-wordpress-pagestimberacfpro

解决方案


推荐阅读