Display Category Images in Navigation

To display the images of categories in the main navigation menu, we need to update two files.

Firstly in Model file. (/app/code/core/Mage/Catalog/Model/Observer.php)

Update following code in Function Name: _addCategoriesToMenu


$categoryData = array( 
        'name' => $category->getName(),
        'id' => $nodeId,
        'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
        'is_active' => $this->_isActiveMenuCategory($category),
        'thumbnail' => Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()
);

Then go into Html folder. (app/code/core/Mage/Page/Block/Html/Topmenu.php)

Update the following line of code at line 128 in

Function name: _getHtml


$urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');
$img = '<img src="'.$urls.'" />';

$html .= '
  • _getRenderedMenuItemAttributes($child) . '>'; $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '>' . $this->escapeHtml($child->getName()) . ' '.$img.' </a>';
  • Display product count of a category in main navigation

    To display Product Count of a particular category in the main navigation, just include the following code in function _addCategoriesToMenu() of the observer file. The Observer file is located at appcodecoreMageCatalogModelObserver.php

    
    $prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
    			$prodCount = $prodCollection->count();
    			if($prodCount=='0')
    			{
    				$prodCounts = '';
    			}
    			else
    			{
    				$prodCounts = ' ('.$prodCount.')';
    			}
    			$categoryData = array(
                    'name' => $category->getName().$prodCounts,
                    'id' => $nodeId,
                    'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
                    'is_active' => $this->_isActiveMenuCategory($category),
    				'thumbnail' => Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()
                );
    

    Continue reading

    How to add excerpt on a Page in WordPress without plugin

    To add an excerpt field in WordPress Pages like we have in Posts, just paste the following code to your functions.php and have fun !!

    add_post_type_support( 'page', 'excerpt' );