我试着用下面的代码检查数组是否存在,问题是当getFieldOrder('image_gal')
里面没有图像时它会返回这个错误。如何在使用魔域时检查数组是否存在
错误输出
Warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/sritamac/public_html/wp-content/plugins/magic-fields/get-custom.php on line 306
Warning: sort() expects parameter 1 to be array, null given in /home/sritamac/public_html/wp-content/plugins/magic-fields/get-custom.php on line 307
阵列码:
<?php
//var
$images = getFieldOrder('image_gal');
if (is_array($images)) {
foreach ($images as $image) {
if (get('image_gal', 1, $image) == TRUE) { //check if image_gallery_image has image
?>
<div id="wrap">
<ul id="mycarousel" class="jcarousel-skin-tango">
<?php
$images = getFieldOrder('image_gal');
foreach ($images as $image) { //loop image
?>
<li>
<a class="group3" href="<?php echo get('image_gal', 1, $image);?>">
<img src="<?php echo get('image_gal', 1, $image);?>" width="150" height="150" alt="" />
</a>
</li>
<?php
}
?>
</ul>
</div>
<?php
break;
}
}
}
?>
即时通讯使用这个主题http://www.s5themes.com/theme/webfolio/和WordPress版本是3.2.1。
魔术字段插件http://magicfields.org/
这是正确的,你是覆盖你的图像变量内foreach循环?如果是这样,将is_array($ images)更改为!empty($ images) – Oliver 2013-03-04 03:45:38
错误仍然相同..我的问题与此人相同https://groups.google.com/forum/?fromgroups=#!topic/magic-字段/ Sw4KxMAvQ_A仍然没有解决方案.. – rusly 2013-03-04 03:51:40