Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

category
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

hi, really need your help

how to get category name with sub category at Mage->catalog->Block->Product->NewHTML.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

Can you please elaborate on your question or give us an image to work off of?

I’m not really sure what you are asking right now.

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

hi @sherrie,

I’m working at CMS->Manage Pages->homepage using block. At the homepage I’m going to display Items image, price, title, product’s url, and the category’s url.

at this point I’m only confuse to display the category’s url. The problem is “how to get the category’s url”

thanks for your reply

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

You can figure out the category ID by going to Manage Categories and clicking on the category you need the ID for - when it loads that category to edit it, you will see the category ID in the address bar of your browser. Hopefully that’s what you’re asking, I’m still not quite sure.

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

Um, arghh, got wrong place to ask but Its not what I’m talking about.. anyway thanks.

actually I need a code to get the category url,

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

Not 100% sure but you may want to play with this code (copy from ‘left.phtml’)

<?php foreach ($_categories as $_category): ?>
                        <?php 
if($_category->getIsActive()): ?>
                        
<li>
                            <
a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
                        </
li>
                        
<?php endif; ?>
                    <?php 
endforeach ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

it’s perfect @chinesedream,

is there another code that get the product category and its sub-category ?

thanks for your quick reply

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

This is what I got for sub-categories

<div class="cat-nav-table">    
<?php $i=0; foreach ($this->getCurrentChildCategories() as $_childCategory): ?>
<?php 
if ($i>12): continue; endif; ?>    
        
   
<ul class="model">   
        <
li>     <a href="<?=$this->getCategoryUrl($_childCategory)?>"<?if ($this->isCategoryActive($_childCategory)):?> class="activeNav"<?endif?>>
            <
img src="<?=$_childCategory->getImageUrl()?>" alt="<?=$_childCategory->getName()?>" />   </a>   </li>    
          <
li<?=$_childCategory->getName()?> </li>  
        </
ul>      
     
  
<?php $i++; endforeach; ?>
            <?php 
for($i;$i&#x12;!=0;$i++): ?> 
                
<?php endfor ?>
   
         
<div class="clear"></div>   
</
div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

thanks,

$this->getCurrentChildCategories() always give me an error, I don’t know why. It says : Error Submission Form,

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

I need to get a product category and its sub-category, not current category..
means that : I make a new homepage, that could have the ability to show all products’ name, price, category, image.

so , I need to make a function to create that.

Now , I can get the category_ids of a product

$_product->_data['category_ids']

but it is only give the category id, not its category name and sub-category name…

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

hi I created this code :

$_categories Mage::helper('catalog/category')->getStoreCategories();
    
$_categories_name $_categories_path = array();

    foreach (
$_categories as $_category) :
        
$aIdxs explode(','Mage::getModel('catalog/category')->setData($_category->getData())->getAllChildren());
        
//echo Mage::helper('catalog/category')->drawItemAll($_category).$_category->getId();
        
if ($_category->getIsActive()) :
            foreach (
$aIdxs as $idx => $iCatIdx) :
                if (
$iCatIdx 2{
                    $_categories_name[$iCatIdx] 
$this->htmlEscape($_category->getName());
                    
$_categories_path[$iCatIdx] Mage::getModel('catalog/category')->setData($_category->getData())->getUrl();
                
}
            
endforeach;
        endif;
    endforeach;

I don’t know if this code is good enough or not…

please, someone tell me…

thanks

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