Tags based on frequency from a 'tags' field.


/ Published in: PHP
Save to your folder(s)

Simple tag links from a database with tags stored in a field as 'tag,tag,tag,tag'.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. //MySQL query for tags.
  4. $tag_limit = 20;
  5. $mysql_tags = "SELECT tags FROM entries LIMIT $tag_limit";
  6. $mysql_qtags = mysql_query($mysql_tags) or die(mysql_error());
  7.  
  8. $tags = array();
  9.  
  10. while ($row = mysql_fetch_array($mysql_qtags)) {
  11. $row_tag_array = split(",", $row[0]);
  12. foreach ($row_tag_array as $newtag) {
  13. if (array_key_exists($newtag, $tags)) {
  14. if ($tags[$newtag] < 200) {
  15. $tags[$newtag] = $tags[$newtag] + 20;
  16. }
  17. }
  18. else {
  19. $tags[$newtag] = 100;
  20. }
  21. }
  22. }
  23.  
  24. foreach ($tags as $tag => $size) {
  25. echo "<a style=\"font-size: $size%;\" href=\"?t=$tag\">$tag</a> "; }
  26. ?>

URL: http://underscoreundefined.co.cc/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.