2

After moving magento to a other host everything seems to work except on homepage.

Only the top is being loaded untill the call for some category listing. See the code below. Something doesn't work on this new host.

When I check the error log I see:

PHP Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH) in /home/xxx/domains/xxx.nl/public_html/app/design/frontend/rwd/default/template/catalog/navigation/category_listing.phtml on line 24, referer: http://www.xxx.nl/

http://phpcodechecker.com/ finds no errors. I'm no php coder. Anyone who knows what could be wrong? It works on the old host.

<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>

<div class="category-products">
    <ul class="products-grid products-grid--max-4-col lalala">                            
        <? foreach ($_categories as $_category):?>
        <? if($_category->getIsActive()): ?>
        <?php $cur_category=Mage::getModel('catalog/category')->load($_category->getId()); ?>
        <?php $layer = Mage::getSingleton('catalog/layer'); ?>
        <?php $layer->setCurrentCategory($cur_category); ?>
        <? if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
        <li class="item">
            <a href="<?php echo $this->getCategoryUrl($_category) ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
                <img src="<?php echo $_imageUrl ?>" width="100%" height="auto" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
            </a>
            <h3 class="koppie"><?php echo $this->htmlEscape($_category->getName()) ?></h3>
        </li>
        <? if($_description=$this->getCurrentCategory()->getDescription()):?>
        <p class="category-description">
            <?php echo $_description ?></p>
        <?php endif; ?>
        <? endif; ?>
        <? endif; ?>
        <?php endforeach; ?>
    </ul>
</div>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>

EDIT

<?php $_maincategorylisting=$this->getCurrentCategory() ?>
<?php $_categories=$this->getCurrentChildCategories() ?>

<div class="category-products">
    <ul class="products-grid products-grid--max-4-col lalala">                            
        <?php foreach ($_categories as $_category): ?>
        <?php if($_category->getIsActive()); ?>
        <?php $cur_category=Mage::getModel('catalog/category')->load($_category->getId()); ?>
        <?php $layer = Mage::getSingleton('catalog/layer'); ?>
        <?php $layer->setCurrentCategory($cur_category); ?>
        <?php if($_imageUrl=$this->getCurrentCategory()->getImageUrl()); ?>
        <li class="item">
            <a href="<?php echo $this->getCategoryUrl($_category) ?>" title="<?php echo $this->htmlEscape($_category->getName()); ?>">
                <img src="<?php echo $_imageUrl ?>" width="100%" height="auto" alt="<?php echo $this->htmlEscape($_category->getName()); ?>" />
            </a>
            <h3 class="koppie"><?php echo $this->htmlEscape($_category->getName()); ?></h3>
        </li>
        <?php if($_description=$this->getCurrentCategory()->getDescription()); ?>
        <p class="category-description"><?php echo $_description ?></p>
        <?php endif; ?>
        <?php endif; ?>
        <?php endif; ?>
        <?php endforeach; ?>
    </ul>
</div>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
  • I did noticed some : instead of ; but it didn't fix it when changing it. – user123 May 18 '15 at 12:56
4

You are using php short tags and they are not enabled in your php configuration.
For example, this line <? foreach ($_categories as $_category):?> should be <?php foreach ($_categories as $_category):?>.
There are also other lines like this. Replace every <? (notice the space after the question mark) with <?php (again a space after "php").
You can also enable the short tags for php , but making your template clean ensures it works independent of the short tag configuration.

  • hey thanks, but still no luck, I have an other error now: unexpected 'endif' on line 20 which is the first endif below the description. I have updated the code. – user123 May 18 '15 at 13:27
  • Now you have <?php if($_description=$this->getCurrentCategory()->getDescription()); ?>. a ; instead of ':'. Actually for all your if statements have a ; at the end instead of : – Marius May 18 '15 at 13:29
  • I had the '<?' in totally different line than the error suggested. After fixing that to '<?php' the page started working. – Webninja Dec 13 '17 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.