How to display tags product in view.phtml of Magento

試著忘記壹切 提交于 2019-12-02 17:50:43

问题


I created new theme and use them for creating product. In view page, I don't see product tags. I review view.pthml in default and know that the tags in "echo $this->getChildHtml('product_additional_data') ", my view.phtml has it too but why it don't display tags

plz, any advice


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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".



来源:https://stackoverflow.com/questions/2053776/how-to-display-tags-product-in-view-phtml-of-magento

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