【发布时间】:2015-04-19 15:49:42
【问题描述】:
我一直在寻找解决此错误的方法。我只是想要一些建议,因为我认为这是我缺少的一些小东西。
我正在尝试使用灵活的内容从使用 ACF pro 设置的选项页面获取 url 字段和图像字段。我正在获取数据,但不是作为字符串变量。
这是错误的屏幕截图。 新链接http://redrocketwebsitedesign.co.uk/Array_error2.png
以及生成它的代码。
<ul class="list-inline"><li>
<p>Follow us on</p>
</li>
<?php //Options: Social icons
// check if the flexible content field has rows of data
if( have_rows('social_icon', 'option') ):
// loop through the rows of data
while ( have_rows('social_icon', 'option') ) : the_row();
if( get_row_layout() == 'social_icon' ):
$image = get_sub_field_object('social_image', 'option');
if( $image ){
?>
<li>
<a href="<?php echo the_sub_field('social_link', 'option'); ?>" target="_blank">
<img class="img img-responsive" src="<?php echo $image[7]; ?>" alt="<?php echo $image[alt]; ?>"/>
</a>
<?php var_dump('Vardump <br />') ?>
<?php var_dump($url) ?>
<?php var_dump('<br /> Image array <br />') ?>
<?php var_dump($image) ?>
<?php var_dump('<br /> Image link <br />') ?>
<?php var_dump($image['7']) ?>
</li>
<?php
}
endif;
endwhile;
else :
// no layouts found
endif;
?>
</ul>
任何帮助将不胜感激:-]
$social_image 是 $field_name,存储为图像数组。当我 print_r $image 时,这就是结果。我想我已经接近能够从数组中选择正确的字符串了。
Image array
`" array(22) { ["ID"]=> int(138) ["key"]=> string(19) "field_54e47a9b7f735" ["label"]=> string(12) "Social Image" ["name"]=> string(12) "social_image" ["prefix"]=> string(0) "" ["type"]=> string(5) "image" ["value"]=> array(18) { ["ID"]=> int(105) ["id"]=> int(105) ["title"]=> string(11) "Tripadvisor" ["filename"]=> string(24) "footertripadvisorNEW.png" ["url"]=> string(83) "http-link" ["alt"]=> string(11) "Tripadvisor" ["author"]=> string(1) "1" ["description"]=> string(0) "" ["caption"]=> string(0) "" ["name"]=> string(20) "footertripadvisornew" ["date"]=> string(19) "2015-02-10 16:13:27" ["modified"]=> string(19) "2015-02-18 11:52:15" ["mime_type"]=> string(9) "image/png" ["type"]=> string(5) "image" ["icon"]=> string(68) "http://localhost:8888/wordpress/wp-includes/images/media/default.png" ["width"]=> int(50) ["height"]=> int(50) ["sizes"]=>`
..等等。
【问题讨论】:
-
能否提供api-template.php文件的第895行?
-
我已经修改了这个问题。在 api-template 的第 900 行下面开始 /* get_sub_field_object()。我想我应该使用这个函数而不是 get_sub_field。
标签: arrays wordpress while-loop options advanced-custom-fields