Php and css label cloud effect

Source: Internet
Author: User
Php and css label cloud effect

  1. Function createTagCloud ($ tags)
  2. {
  3. // I pass through an array of tags
  4. $ I = 0;
  5. Foreach ($ tags as $ tag)
  6. {
  7. $ Id = $ tag ['id']; // the tag id, passed through
  8. $ Name = $ tag ['tag']; // the tag name, also passed through in the array
  9. // Using the mysql count command to sum up the tutorials tagged with that id
  10. $ SQL = "SELECT COUNT (*) AS totalnum FROM tutorials WHERE tags LIKE '%". $ id. "%' AND published = 1 ";
  11. // Create the resultset and return it
  12. $ Res = mysql_query ($ SQL );
  13. $ Res = mysql_fetch_assoc ($ res );
  14. // Check there are results ;)
  15. If ($ res)
  16. {
  17. // Build an output array, with the tag-name and the number of results
  18. $ Output [$ I] ['tag'] = $ name;
  19. $ Output [$ I] ['num'] = $ res ['totalnum'];
  20. }
  21. $ I ++;
  22. }
  23. /* This is just calling another function that does a similar SQL statement, but returns how many pieces of content I have */
  24. $ Total_tuts = $ this-> getNumberOfTutorials ();
  25. // Ugh, XHTML in PHP? Slap my hands-this isn't best practice, but I was obviusly feeling lazy
  26. $ Html ='
      ';
    • // Iterate through each item in the $ output array (created above)
    • Foreach ($ output as $ tag)
    • {
    • // Get the number-of-tag-occurances as a percentage of the overall number
    • $ Ratio = (100/$ total_tuts) * $ tag ['num'];
    • // Round the number to the nearest 10
    • $ Ratio = round ($ ratio,-1 );
    • /* Append that classname onto the list-item, so if the result was 20%, it comes out as cloud-20 */
    • $ Html. ='
    • '. $ Tag ['tag'].'
    • ';
    • }
    • // Close the UL
    • $ Html. ='
    ';
  27. Return $ html;
  28. }

2. css code section/* delete the default list style to make it a common list */

  1. . Home-item ul. tagcloud
  2. {
  3. List-style-type: none;
  4. Margin: 0px;
  5. Padding: 0px;
  6. }
  7. /* Set the li style */
  8. . Home-item ul. tagcloud li
  9. {
  10. Display: inline! Important;
  11. Margin-right: 15px;
  12. Line-height: 2em;
  13. }
  14. . Home-item ul. tagcloud li
  15. {
  16. Display: inline;
  17. }
  18. /* Tag cloud effect */
  19. . Home-item ul. tagcloud li. cloud-10
  20. {
  21. Font-size: 110%;
  22. }
  23. . Home-item ul. tagcloud li. cloud-20
  24. {
  25. Font-size: 120%;
  26. }
  27. . Home-item ul. tagcloud li. cloud-30
  28. {
  29. Font-size: 130%;
  30. }
  31. /*************************************
  32. You get the idea, I'm skipping a few
  33. *************************************/
  34. . Home-item ul. tagcloud li. cloud-90
  35. {
  36. Font-size: 190%;
  37. }
  38. . Home-item ul. tagcloud li. cloud-100
  39. {
  40. Font-size: 200%;
  41. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.