从WordPress高级自定义字段数组中获取正确的图片网址?

时间:2018-08-07 02:39:12

标签: wordpress wordpress-theming advanced-custom-fields

WordPress newb。

$article_data = get_field('article_item');
  foreach ($article_data as $key => $item) {
    $footerImg = (!empty($item['bottom_image'])) ? $item['bottom_image'] : NULL;
    $url = implode( ', ', $footerImg );
    echo $url;

  }

输出如下:

2345, 
67899, 
boston_skyline, 
boston_skyline.jpg, 
http://localhost:8000/bostontheme/images/2018/08/boston_skyline.jpg, 
2018-08-07 01:24:21

如何在其中抓取图像字符串,以便可以执行以下操作:

<img src="<?php echo $url ?>" />

当我这样做

print_r($item);

我得到以下输出:

Array ( 
[bottom_image] => Array ( 
[ID] => 67899 
[id] => 67899 
[title] => boston_skyline 
[filename] => boston_skyline.jpg 
[url] => http://localhost:8000/bostontheme/images/2018/08/boston_skyline.jpg

1 个答案:

答案 0 :(得分:1)

您只需要$item["bottom_image"]["url"]