-1

我正在尝试执行如下代码

但在ul中显示错误 为

语法错误:预期:exit、if、标识符、变量、echo、do、while、for、foreach、endforeach、declare、switch、break、continue、function、return、try、throw、use、global、unset、isset、empty , 类, 接口, 数组, {, 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>

任何人请帮助我

4

3 回答 3

1

我不是 100% 确定您要做什么,因为 $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>
于 2012-11-12T12:09:52.123 回答
0

也许 :

<?php endforeach ;?>

你错过;了倒数第三行。

于 2012-11-12T06:29:24.603 回答
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 ?>
于 2012-11-12T06:30:39.897 回答