我目前正在joomla buiding一個網站,並使用k2來管理內容 我正在創建一個模板在k2中,爲item.php。我希望使用額外的字段在項目上顯示標題圖像。k2 item.php額外的字段顯示默認圖像,如果留空
我已成功地實現此使用以下
走向的定位文件
<?php
$extrafields = array();
foreach($this->item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
?>
頂在需要
<?php if($extrafields[2]!=''):?> <!-- if filled in, then call data -->
<?php echo $extrafields[2];?> <!-- actual data call -->
<?php endif; ?>
我已經成功,如果我填在額外的領域,我得到我的標題圖像正是我想要的地方,我的問題是,如果我離開該領域的空白,是指恢復到默認的圖像,但insted的我碰到下面的錯誤
Notice: Undefined offset: 2 in (URL)\item.php on line 194
我不知道在哪裏出了問題。我確信我需要一個或者一個聲明,但是星期五和我的大腦都被炸了。任何幫助非常感謝!
Iameki
由於曼努埃爾·達拉拉娜,我已經實現了你的建議,但我仍然收到同樣的錯誤。我已經實施它如下
<?php if(isset($extrafields[2]) && $extrafields[2]!=''):?> <!-- if filled in, then call data -->
<?php echo $extrafields[2];?> <!-- actual data call -->
<?php endif; ?>
請讓我知道,如果我不正確地實施它。
你可以發表你的item.php地方,比如http://codebin.org? –