Question

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?

Was it helpful?

Solution

to get programmatically popular tag use this code

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

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

OTHER TIPS

Add this to the Content section of your hopepage:

{{block type="tag/all" name="tags_all" template="tag/popular.phtml"}}

updated

$tag_model= Mage::getModel('tag/tag');
          $tag_collection= $tag_model->getResourceCollection()
                    ->addPopularity()
                    ->addStatusFilter($model->getApprovedStatus())
                    ->addProductFilter($ProductId)
                    ->setFlag('relation', true)
                    ->addStoreFilter(Mage::app()->getStore()->getId())
                    ->setActiveFilter()
                    ->load();

    $mytags=$tag_collection->getItems();

       foreach ($mytags as $tag) {
               echo  $tag->getTaggedProductsUrl();
               echo $tag->getName();

                      }

I am giving this answer because the other answers are not working for me. I archived in the following way:

<?php $tagblockobj = Mage::getBlockSingleton('tag/all');?>
 <?php if( sizeof($tagblockobj ->getTags()) > 0 ): ?>
   <?php foreach($tagblockobj ->getTags() as $tag):?>
     <a href="<?php echo $tag->getTaggedProductsUrl()?>" class="tags-b"><?php echo $tag->getName()?></a>
   <?php endforeach;?>  
 <?php else: ?>
      <p class="note-msg"><?php echo $this->__('There are no tags available.') ?></p>
 <?php endif; ?>  
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top