In Magento, If you are on category page than it's easy to get current category.
$_current_category=$this->getCurrentCategory();
or,
$_current_category = Mage::registry('current_category');
I needed Current Category on product info page and on the footer.phtml files. Because I had custom background set for each Category. So, Below code helped me to find the Current Category in my Magento's phtml file.
$hb = ''; $current_category = Mage::registry('current_category'); if(!is_object($current_category)) { $current_product = Mage::registry('current_product'); if(is_object($current_product)) { $categories = $current_product->load($current_product->getId())->getCategoryIds(); if (is_array($categories) and count($categories)) { $current_category = Mage::getModel('catalog/category')->load($categories[0]); } } } if(is_object($current_category)) { $body_image = $current_category->getData('body_image'); if(!empty($body_image)) { $hb = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/category/' . $body_image; } }
Visit Here if you want to Get Magento's Current URL
purvi posted on - Tuesday 20th of May 2014 07:21:54 AM
bartz posted on - Saturday 28th of June 2014 10:55:06 AM
I just copied the main code, and done this:
$categoryVars = get_object_vars($current_category);
<span class="category-name"><a href="/<?=$categoryVars['_data']['url_path']?>"><?=$categoryVars['_data']['name']?></a></span>