1

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?

0

to get programmatically popular tag use this code

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

                                ->load();
foreach($collection as $tag)
                            {
                                //code here
                                }
  • hello! You write "to get popular tag", but I get all the tags with your code, not only popular. Anyway seems like this is what I need. Thank you very much – Dmitry Legostev May 7 '15 at 5:31
2

Add this to the Content section of your hopepage:

{{block type="tag/all" name="tags_all" template="tag/popular.phtml"}}
  • Hi, thanks for your answer, but I need to get all tags, not only popular. – Dmitry Legostev May 7 '15 at 5:28
  • the block tag/all will give you all tags. The block uses the popular template but it should display all the tags. – Marius May 7 '15 at 6:17
0

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();

                      }
  • Hi, thank you for the answer, but it doesn't work. I get error: Fatal error: Call to a member function getResourceCollection() on a non-object in app/design/frontend/rwd/default/template/page/html/header.phtml on line 352 – Dmitry Legostev May 7 '15 at 5:27
0

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; ?>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.