Jump to content

Tags on Product page


Tomas LT

Recommended Posts

Hello.

 

Need show product tags on product page.

 

 

I find this code:

<ul class="producttags">

    {foreach from=Tag::getProductTags(Tools::getValue('id_product')) key=k item=v}
        {foreach from=$v item=value}
            <li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
        {/foreach}
    {/foreach}
</ul>

But tags are showing two times:

tag1,

tag2,

tag3,

tag1,

tag2,

tag3

 

 

How to display each tag one time?

 

Prestashop 1.6.0.11

Link to comment
Share on other sites

where you added this code? perhaps in some foreach loop and this is why you see it 2 times

 

I add this code in product.tpl file. Not in other foreach loop. I test different positions in top, middle or end file, but tags displaying two times.

Link to comment
Share on other sites

  • 2 weeks later...

Maybe tags are shown twice because of 2 languages ?

 

Try this code

<ul class="producttags">
    {foreach from=Tag::getProductTags(Tools::getValue('id_product')) key=k item=v}
        {foreach from=$v key=lang_id item=value}
         	{if $cookie->id_lang eq $lang_id}
            	<li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
            {/if}
        {/foreach}
    {/foreach}
</ul>
Link to comment
Share on other sites

  • 5 months later...

I added the following code to my tpl file and it works fine:

   <ul class="producttags">
    {foreach from=Tag::getProductTags(Tools::getValue('id_product')) key=k item=v}
        {foreach from=$v key=lang_id item=value}
            	<li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
        {/foreach}
    {/foreach}
</ul>

But how can I check if the foreach condition isnt empty?

 

I want something like 

 

{if foreach!=empty}

 

code

 

{/if}

Link to comment
Share on other sites

  • 1 month later...

Hello wakabayashi.

 

My project is based on PS1.6.1.1 and I'm trying to use your code in product.tpl:

            {if Tag::getProductTags(Tools::getValue('id_product'))!=""} 
               <ul class="producttags">
                {foreach from=Tag::getProductTags(Tools::getValue('id_product')) key=k item=v}
                  {foreach from=$v key=lang_id item=value}
                      <li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
                  {/foreach}
                {/foreach}
               </ul>
            {/if}

The first conditional if it's working correctly. But I'm getting all the tags without any language filtration. Looks like the key=lang_id it's ignored. Is there any new way in PS1.6.1.1?

 

My best regards.

Edited by pedroserapio (see edit history)
Link to comment
Share on other sites

Found the solution in https://www.prestashop.com/forums/topic/469576-tags-in-product-list-16/

            {if Tag::getProductTags(Tools::getValue('id_product'))!=""} 
               <ul class="producttags">
                {foreach from=Tag::getProductTags(Tools::getValue('id_product')) key=k item=v}
                  {if $k != $lang_id}
                      {continue}
                  {/if}
                  {foreach from=$v item=value}
                      <li><a href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a></li>
                  {/foreach}
                {/foreach}
               </ul>
            {/if}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...