我正在尝试执行以下代码
但 ul 中显示的错误为
语法错误: 期望:退出,if,标识符,变量,echo,do,while,for,foreach,endforeach,declare,switch,break,continue,function,return,try,throw,use,global,unset,isset,empty,class, interface,array,{,include,include_once,eval,require,require_once,print,';',+, - ,!,〜,++, - ,@,new,static,abstract,final,(,$ /强>
我的代码是
<div class="footer">
<div class="footer_top">
<?php $helper = $this->helper('catalog/category') ?>
<?php $counts=$helper->getStoreCategories()->count(); ?>
<?php $cnt=0; $row=0; foreach ($helper->getStoreCategories() as $_category): ?>
<?php if(($i==0)&&($cnt<$count)) ?>
<?php $row++; ?>
<div class="footer_part">
<?php if($row==1):$no=4; ?>
<h2>Navigation</h2>
<?php else : $no=3; ?>
<h2></h2>
<?php endif ?>
<ul>
<?php endif; ?>
<li><a href="<?php echo Mage::getModel('catalog/category')->setData($_category->getData())->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a></li>
<?php $i++; if($i==$no):?>
<?php $i=0;?>
</ul>
</div>
<?php endif; ?>
<?php endforeach ?>
</div>
</div>
有人请帮帮我
答案 0 :(得分:1)
我不是百分之百确定你要做什么,因为$ cnt总是等于0所以你真的不需要检查$cnt<$count
因为foreach只会在数组/对象数大于0
<div class="footer">
<div class="footer_top">
<?php $helper = Mage::helper('catalog/category'); ?>
<?php //$counts = $helper->getStoreCategories()->count(); ?>
<?php $cnt = 0;
$row = 0;
$i == 0;
foreach ($helper->getStoreCategories() as $_category): ?>
<?php if (($i == 0)): $row++; ?>
<div class="footer_part">
<?php if ($row == 1): $no = 4; ?>
<h2>Navigation</h2>
<?php else : $no = 3; ?>
<h2></h2>
<?php endif; ?>
<ul>
<?php endif; ?>
<li><a href="<?php echo $_category->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a></li>
<?php $i++; ?>
<?php if ($i == $no): $i = 0; ?>
</ul>
</div>
<?php endif; ?>
<?php endforeach ?>
</div>
</div>
答案 1 :(得分:0)
可能是:
<?php endforeach ;?>
你错过了最后一行的;
。
答案 2 :(得分:0)
我想你还有一个额外的
<?php end if ?>
在<ul>
之后。
请检查......这是代码......
<?php $helper = $this->helper('catalog/category') ?>
<?php $counts=$helper->getStoreCategories()->count(); ?>
<?php $cnt=0; $row=0; foreach ($helper->getStoreCategories() as $_category): ?>
<?php if(($i==0)&&($cnt<$count)) ?>
<?php $row++; ?>
<div class="footer_part">
<?php if($row==1):$no=4; ?>
<h2>Navigation</h2>
<?php else : $no=3; ?>
<h2></h2>
<?php endif ?>
<ul>
//(deleted one endif here)
<li><a href="<?php echo Mage::getModel('catalog/category')->setData($_category->getData())->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a></li>
<?php $i++; if($i==$no):?>
<?php $i=0;?>
</ul>
</div>
<?php endif; ?>
<?php endforeach ?>