Jump to content
Sign in to follow this  
caparuni

[TIPS] Random Tag

Recommended Posts

bikin blok tag jadi random tiap kali load page.
edit .../classes/Tag.php (sekitar line 111)

cari :

ORDER BY times DESC



ganti dengan :

ORDER BY RAND()




oia secara default, tag hanya di tampilkan sebanyak 10, nah kalo mo ubah jumlah tag yg tampil,

edit .../modules/blocktags/blocktags.php (skitar line 35)

cari :

$tags = Tag::getMainTags(intval($params['cookie']->id_lang));



ganti dengan :

$tags = Tag::getMainTags(intval($params['cookie']->id_lang),25);


dmn 25 adalah jumpah tag yg akan di tampilkan. nah ganti suka2 lu ;)


:: semoga berguna ::

Share this post


Link to post
Share on other sites

Thanks dah share. Tapi kalau mau lebih advance lagi, seharusnya bisa di order berdasar jumlah produk dari tag tersebut. font size nya juga menyesuaikan. semisal tag widget di wordpress.

Share this post


Link to post
Share on other sites

If i change code how you described, i get empty Tags block....
Any ideas?

Thanks,
W.

Share this post


Link to post
Share on other sites

are u sure u already input the tag for the product? to make sure please check directly to sql, since theres no menu about tag in back-office (cmimw).
please check ps_tag & ps_product_tag in sql

Share this post


Link to post
Share on other sites

Yes, i have, becouse it shows in tag block.
You can check here: www.mojprostor.net on the lower right corner.
But those tags don't show random. I wanted them to be random, but i have changed in Tag.php and blocktags.php as you described. Anything else? I hope i understood correct your instructions :)

Thanks,
W.

Share this post


Link to post
Share on other sites

hmmm...

this is my .../classes/Tag.php

   static public function getMainTags($id_lang, $nb = 10)
   {
       return Db::getInstance()->ExecuteS('
       SELECT t.name, COUNT(pt.id_tag) AS times
       FROM `'._DB_PREFIX_.'product_tag` pt
       LEFT JOIN `'._DB_PREFIX_.'tag` t ON t.id_tag = pt.id_tag
       LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = pt.id_product
       WHERE id_lang = '.intval($id_lang).'
       AND p.active = 1
       GROUP BY t.id_tag
       ORDER BY RAND()
       LIMIT 0, '.intval($nb));
   }



see the RAND( )


this is my .../modules/blocktags/blocktags.php

   function hookLeftColumn($params)
   {
       global $smarty;
       $tags = Tag::getMainTags(intval($params['cookie']->id_lang),25);
       if (!sizeof($tags))
           return '';
       $maxFontSize = 16;
       $minFontSize = 10;
       $maxNumber = intval($tags[0]['times']);
       $classPrefix = 'tag_level';
       for ($i = 0; $i < sizeof($tags); ++$i)
       {
           $tags[$i]['fontSize'] = floor(($maxFontSize * $tags[$i]['times']) / $maxNumber);
           if ($tags[$i]['fontSize'] < $minFontSize)
               $tags[$i]['fontSize'] = $minFontSize;
           // 2nd version: use CSS class
           $tags[$i]['class'] = $classPrefix.$tags[$i]['times'];
           if ($tags[$i]['times'] > 3)
               $tags[$i]['class'] = $classPrefix;
       }
       $smarty->assign('tags', $tags);
       return $this->display(__FILE__, 'blocktags.tpl');
   }

Share this post


Link to post
Share on other sites

btw, try to delete all files under .../tools/smarty/compile

Share this post


Link to post
Share on other sites

THANKS, now it works!!! i needed to change whole section.

Much appreciated!!
W.

edit: didn't need to delete anything... :)

Share this post


Link to post
Share on other sites

Sorry, but I don't understand why it need code
in /modules/blocktags/blocktags.php

if ($tags[$i]['times'] > 3)
               $tags[$i]['class'] = $classPrefix;



if all tags are lagger than 3, they view the smallest
I don't find in /modules/blocktags/blocktags.tpl any {$tag.fontSize}

I'm try:

function hookLeftColumn($params)
   {
       global $smarty;

       $numberTags = intval(Configuration::get('BLOCKTAGS_NBR'));
       $tags = Tag::getMainTags(intval($params['cookie']->id_lang), $numberTags);
       if (!sizeof($tags))
           return '';
       $maxFontSize = 18;
       $minFontSize = 10;
       $maxNumber = intval($tags[0]['times']);
/*
       In  /classes/Tag.php method getMainTags() order in SQL must be ORDER BY times DESC
*/
       $classPrefix = 'tag_level';
       for ($i = 0; $i < sizeof($tags); ++$i)
       {
           $tags[$i]['fontSize'] = floor(($maxFontSize * $tags[$i]['times']) / $maxNumber);
           if ($tags[$i]['fontSize'] < $minFontSize)
               $tags[$i]['fontSize'] = $minFontSize;

           $tagClass = floor(($tags[$i]['times']) / $maxNumber) + 1;
           if($tagClass > 5)
               $tagClass = 5;

           $tags[$i]['class'] = $classPrefix.$tagClass;
       }
       $smarty->assign('tags', $tags);
       return $this->display(__FILE__, 'blocktags.tpl');
   }


and change in global.css

a.tag_level5 { font-size: 1.8em; font-weight:bold;}
a.tag_level4 { font-size: 1.6em; font-weight:bold;}
a.tag_level3 { font-size: 1.4em;}
a.tag_level2 { font-size: 1.2em;}
a.tag_level1 { font-size: 1em; color:#888!important;}



and tags view correct!

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More