0

I want to make a landing page for Magento 1.9.3.4. What I got is the following:

Head category: Computer

Sub-categories from Computer: Harddisk, Monitor, Cables, Keyboards.

I want to make a page for "Computer" where all the sub-categories will be shown and 8 products from each sub-category.

How can I do this in best way?

1 Answer 1

0

I got it:

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $categoryId = 48;?>
<?php $category = Mage::getModel('catalog/category')->load($categoryId) ?>
<?php $_categories = $category->getChildrenCategories() ?>

<?php if (count($_categories) > 0): ?>
    <?php foreach($_categories as $_category): ?>
        <div class="row">
            <div class="container">
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"><?php echo $_category->getName() ?></a>
                <?php
                    $_category = Mage::getModel('catalog/category')->load($_category->getId());
                    $_productCollection = Mage::getResourceModel('catalog/product_collection')
                        ->addCategoryFilter($_category)
                        ->addAttributeToSelect('*');
                ?>
                <ul class="products-grid row-4">
                    <?php $i = 0; foreach ($_productCollection as $_product): $i++; ?>
                        <?php $_product = Mage::getModel('catalog/product')->load($_product->getId()) ?>

                        <li class="item col-md-3 col-sm-4 col-xs-6">
                            <div class="product-content">
                                <div class="product-top">
                                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image">
                                        <?php $productImage = $this->helper('catalog/image')->init($_product, 'small_image')->resize($size['width'], $size['height']); ?>
                                        <?php $productImageHover = $this->helper('catalog/image')->init($_product, 'thumbnail')->resize($size['width'], $size['height']); ?>
                                        <?php if(!$lazyLoad): ?>
                                            <?php $baseImg = $productImage; $baseImgHover = $productImageHover; ?>
                                        <?php endif ?>
                                        <img id="product-collection-image-<?php echo $_product->getId(); ?>" src="<?php echo $baseImg ?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="img-responsive<?php if($lazyLoad): ?> lazy<?php endif ?>" data-original="<?php echo $productImage ?>"/>

                                        <?php if(basename($_product->getData('thumbnail')) != basename($_product->getData('small_image'))): ?>
                                            <img src="<?php echo $baseImgHover ?>"
                                            alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="img-responsive img-hover<?php if($lazyLoad): ?> lazy<?php endif ?>" data-original="<?php echo $productImage ?>"/>
                                        <?php endif ?>
                                    </a>

                                    <div class="add-to-cart">
                                        <?php if ($_product->isSaleable()): ?>
                                            <?php if ($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()): ?>
                                                <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-cart" onclick="setLocation('<?php echo $_product->getProductUrl() ?>')"><span class="icon pe-7s-shopbag"></span><span class="text"><?php echo $this->__('Add to Cart'); ?></span></button>
                                            <?php else: ?>
                                                <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span class="icon pe-7s-shopbag"></span><span class="text"><?php echo $this->__('Add to Cart'); ?></span></button>
                                            <?php endif; ?>
                                        <?php else: ?>
                                            <p><?php echo $this->__('Our of stock') ?></p>
                                        <?php endif; ?>
                                    </div>

                                </div>

                                <div class="product-desc">
                                    <h5 class="product-name">
                                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a>
                                    </h5>
                                    <p class="bk-product-short-description">
                                        <?php echo substr($_product->getShortDescription(),0,40).'...'; ?>
                                    </p>
                                    <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>
                                    <?php
                                        if ($this->getChild('name.after')) {
                                            $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                                            foreach ($_nameAfterChildren as $_nameAfterChildName) {
                                                $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                                                $_nameAfterChild->setProduct($_product);
                                                echo $_nameAfterChild->toHtml();
                                            }
                                        }
                                    ?>

                                </div>

                            </div>
                        </li>
                    <?php endforeach ?>
                </ul>
            </div>
        </div>
    <?php endforeach; ?>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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