Template Home PHTML – Display All Product Tags on Homepage

homephtmltagstemplate

I can't understand how can I display all tags in my homepage?

There's a workable solution to display a product's tags in a product page with this code:

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

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

But it doesn't work in home page.

I get error

Fatal error: Call to a member function getItems() on a non-object in app/code/core/Mage/Tag/Block/Product/List.php on line 45

What should I do?

Best Answer

to get programmatically popular tag use this code

    $tagmodel = Mage::getModel('tag/tag');
    $collection = $tagmodel->getResourceCollection()
                                ->addPopularity()

                                ->load();
foreach($collection as $tag)
                            {
                                //code here
                                }
Related Topic