我試着用下面的代碼檢查數組是否存在,問題是當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