How to display tags product in view.phtml of Magento

百般思念 提交于 2019-12-02 07:42:43

This is what I did after about 4 hours of research.

<?php
// instantiate the tags class for products
$_tags = new Mage_Tag_Block_Product_List();
?>

<ul class="product-tags">
<?php foreach($_tags->getTags() as $tag):?>
    <li><a href="<?=$tag->getTaggedProductsUrl()?>"><?=$tag->getName()?></a></li>
<?php endforeach;?>
</ul>

I don't like having to instantiate the class, so if I find a more elegant way I'll update my post. But at least it a php only solution.

Does your catalog.xml's catalog/product_view block define something like this?

<block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />

In my Modern Theme store the tags are displayed using the template/tag/list.phtml hint path.

Hope this helps.

@Boss Ninja: it works perfectly if your tag.xml file is enabled in layout directory (app/design/frontend/default/default/layout).

Define at XML layout in catalog_product_view section:

<block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />

And then in your phtml where you want it to display:

<?php echo $this->getChildHtml('product_additional_data') ?>

Ensure that Mage_Tag module is enabled at "System --> Configuration --> Advanced".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!