Magento Forum

   
[HELP] get category url
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

how to get category url base on id ?

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

got it,

First I make my new function

public function drawItemHw($category$aIds{

        $item 
= array();
        if (!
$category->getIsActive()) return $item;

        
$children $category->getChildren();
        
$hasChildren $children && $children->count();
        if (
$hasChildren{
            
foreach ($children as $child{
                
if ($child->getIsActive()) {
                    $tempItem 
$this->drawItemHw($child$aIds);
                    if (!empty(
$tempItem)) $item array_merge($item$tempItem);
                
}
            }            
        } 
else if (in_array($category->getId(), $aIds)) {
            $item[] 
= array($category->getId(), $category->getName(), $this->getCategoryUrl($category));
        
}
        
return $item;
    
}


    
public function getDrawItemHw($ids=null{
        $aIds 
explode(','$ids);
        
$aItem = array();
        
$_categories $this->getStoreCategories();

        foreach (
$_categories as $_category):
            
$tempItem $this->drawItemHw($_category$aIds);
            if (!empty(
$tempItem)) $aItem array_merge($aItem$tempItem);
        endforeach;

        return 
$aItem;
    
}

then call it from product’s category you have on it

 
Magento Community Magento Community
Magento Community
Magento Community
 
veeliks
Jr. Member
 
Total Posts:  1
Joined:  2009-06-26
 

Could you (or anyone else) perhaps give some more info on how to implent this, i.e. tell where to add the public functions and give an example how to call the actual function from a template page. Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
magedev
Sr. Member
 
Avatar
Total Posts:  117
Joined:  2009-06-01
 

If you just need category Url based on category id you can use snippet below:

$categoryId $put_here_your_category_id;
 
$category Mage::getModel('catalog/category')->load($categoryId);
 
$categoryUrl $category->getUrl();
 
$categoryName $category->getName();

and obviously if you just need url you can use shortcut:

$categoryUrl Mage::getModel('catalog/category')->load($categoryId)->getUrl();

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top