Magento Forum

   
Category Name? 
 
forward
Jr. Member
 
Total Posts:  2
Joined:  2008-08-14
 

I’m trying to display links to the categories of a product. What I have to start with is $_product which is an instance of class Mage_Catalog_Model_Product. I can display the category url but the name is missing. Anybody know why?

<?php
            $_categories 
$_product->getCategoryCollection();
            foreach(
$_categories as $_category): ?>
              
<a href="<?php echo $_category->getUrl(); ?>">
                
<?php echo $_category->getName(); ?>
              
</a>
          
<?php endforeach ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
LindyKyaw
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2008-01-02
Los Angeles
 

What data did you get when you tries to print out category?

print_r($_category->debug());

 
Magento Community Magento Community
Magento Community
Magento Community
 
forward
Jr. Member
 
Total Posts:  2
Joined:  2008-08-14
 

Thanks for the tip. This is what I get:

Array
(
    
[entity_id] => 3
    [entity_type_id] 
=> 3
    [attribute_set_id] 
=> 3
    [parent_id] 
=> 2
    [created_at] 
=> 2008-08-19 01:35:51
    [updated_at] 
=> 2008-08-27 19:20:02
    [path] 
=> 1/2/3
    [position] 
=> 1
    [level] 
=> 2
    [product_id] 
=> 1
    [url] 
=> http://domain.org/category_name
)

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