Magento Category listing on home page

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

Magento Category listing on home page

Magento Category listing on home page

Here, I wrote the article for Magento Category listing on home page. You can find the how to list the categories on home page and you can also remove the listing of categories which you don’t want to display in home page. You can find here code for it. If you have any query please contact me I will guide you.

Here you can find code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<div class="top-home-category">
<?php 
    $_helper    = $this->helper('catalog/output');
    $_categories =  Mage::getModel('catalog/category')->load(2)->getChildrenCategories()->addAttributeToSort('position', 'asc');
 
    $arrcats = array();
    $rcat_id = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();
 
    foreach($_categories as $_cat)
    {
        foreach($_cat as $ctkey)
            $arrcats[] = $ctkey['entity_id'];
 
        $arrcats = array_unique(array_filter($arrcats, 'is_numeric'));
    }
	// Remove Category which you don't want to display
	$remove_cat = array('8');
    $_categories = array_diff($arrcats,$remove_cat); 
 
    if(count($_categories)>0):
?>
        <div class="category-products">        
        <?php 
            $_collectionSize = count($_categories);
            $_columnCount = 3; 
            $i=0; 
 
            foreach ($_categories as $_category): 
 
                $cur_category = Mage::getModel('catalog/category')->load($_category);
                if ($i++%$_columnCount==0){                         
        ?>
            <ul class="products-grid" >
            <?php   } ?>
            <?php 
                if($cur_category->getIsActive()){
                    if ($_imgUrl = $cur_category->getImageUrl()){
                            $_imgHtml = '< img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($cur_category->getName()).'" title="'.$this->htmlEscape($cur_category->getName()).'" />';
                            $_imgHtml = $_helper->categoryAttribute($cur_category, $_imgHtml, 'image');
                    } 
                } 
            ?>
                <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                    <a class="product-image" href="<?php echo $this->getCategoryUrl($cur_category) ?>" ><?php echo $_imgHtml; ?></a>
                    <h2 class="product-name">
                        <a href="<?php echo $this->getCategoryUrl($cur_category) ?>"><?php echo $_helper->categoryAttribute($cur_category, $cur_category->getName(), 'name') ?></a>
                    </h2>
                    <div class="desc">
                        <?php echo substr($_helper->categoryAttribute($cur_category, $cur_category->getDescription(), 'description'),0, 120) ?>
                    </div>
                    <div class="morelink">
                        <a href="<?php echo $cur_category->getURL(); ?>" class="link">More Info</a>
                    </div>                        
                </li>
    <?php if ($i%$_columnCount==0 || $i==$_collectionSize){ ?>
            </ul>
    <?php } ?>
 
            <?php endforeach ?>
            <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
        </div>
<?php        
    else:
?>    
        <p class="note-msg"><?php echo $this->__('There are no category.') ?></p>        
<?php
    endif;
?>
</div>

Add comment


 

Pin It on Pinterest

Share This