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

Adding category to the product details block (..template/product/view.phtml)
 
Brian2
Member
 
Total Posts:  59
Joined:  2009-01-12
Harrogate, North Yourshire, UK
 

I need to add the category next to the product title in the product details block. The code I have at present is as follows (additional code indicated).  The file is ..template/product/view.phtml. The page does not render the block at all. Any idea what I have done wrong please?

<?php
    $_helper 
$this->helper('catalog/output');
    
$_product $this->getProduct()
    
[additional code starts]$_category $this->getCategory() [additional code ends] 
?>
<script type="text/javascript">
    var 
optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<
div class="product-info-box">
        <
h3 class="product-name-title">
            
<?php echo $_helper->productAttribute($_product$this->htmlEscape($_product->getName()), 'name'?>                         
            [additional code starts]<?php 
echo $_helper->categoryAttribute($_category$this->htmlEscape($_category->getName()), 'name'?>[additional code ends]
        
</h3>
 
Magento Community Magento Community
Magento Community
Magento Community
 
subesh
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2009-01-08
 

$_helper $this->helper('catalog/output');
    
$_product $this->getProduct();
    
$_category=Mage::registry('current_category')->getName();

    echo 
$_category;
 
Magento Community Magento Community
Magento Community
Magento Community
 
Brian2
Member
 
Total Posts:  59
Joined:  2009-01-12
Harrogate, North Yourshire, UK
 

Thanks for your help with this, much appreciated. I have amended the code as below but the page doesn’t render the block.

<?php
    $_helper 
$this->helper('catalog/output');
    
$_product $this->getProduct()
    
$_category=Mage::registry('current_category')->getName(); 
       
?>
<script type="text/javascript">
    var 
optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<
div class="product-info-box">
        <
h3 class="product-name-title">
            
<?php echo $_helper->productAttribute($_product$this->htmlEscape($_product->getName()), 'name'?> <?php echo $_category ?>
        
</h3>
 
Magento Community Magento Community
Magento Community
Magento Community
 
subesh
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2009-01-08
 

<h5 class="product-name">
                
Category<?php echo $_category?>
            
</h5>

This will work.....

after

<h3 class="product-name">
                
<?php echo $_helper->productAttribute($_product$this->htmlEscape($_product->getName()), 'name'?>
            
</h3>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Brian2
Member
 
Total Posts:  59
Joined:  2009-01-12
Harrogate, North Yourshire, UK
 

Sorry to be a pain, I have tried that but still no luck

<?php
    $_helper 
$this->helper('catalog/output');
    
$_product $this->getProduct()
    
$_category=Mage::registry('current_category')->getName(); 
       
?>
<script type="text/javascript">
    var 
optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<
div class="product-info-box">
        <
h3 class="product-name-title">
            
<?php echo $_helper->productAttribute($_product$this->htmlEscape($_product->getName()), 'name'?> 
        
</h3
        <
h5>
        
<?php echo $_category?>
        
</h5>
 
Magento Community Magento Community
Magento Community
Magento Community
 
amine2005
Jr. Member
 
Total Posts:  23
Joined:  2008-09-11
 

in app\design\frontend\default\default\template\catalog\product\list.phtml

<?php echo $_product->getCategory()->getName()?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
subesh
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2009-01-08
 

what is your version........my is 1.1.7

 
Magento Community Magento Community
Magento Community
Magento Community
 
gabi
Jr. Member
 
Total Posts:  10
Joined:  2008-10-02
 

,

 
Magento Community Magento Community
Magento Community
Magento Community
 
amine2005
Jr. Member
 
Total Posts:  23
Joined:  2008-09-11
 

1.2.1

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brian2
Member
 
Total Posts:  59
Joined:  2009-01-12
Harrogate, North Yourshire, UK
 

The code below worked ok. Thanks both for your help with this, it is much appreciated.

<?php echo $_product->getCategory()->getName()?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
vij
Sr. Member
 
Total Posts:  81
Joined:  2009-02-13
 

hi amine2005
i think this will work for u
<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>

<div class="lines"><span class="title"><?php echo $_category->getName() ?></span></div>
<?php endforeach; ?>

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