首页 后端开发 php教程 php与css 标签云效果

php与css 标签云效果

Jul 25, 2016 am 08:56 AM

  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 obviously 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代码部分 /*删除默认的列表样式,使之成为一个普通的清单列表*/

  1. .home-item ul.tagcloud
  2. {
  3. list-style-type:none;
  4. margin:0px;
  5. padding:0px;
  6. }
  7. /*设置li的样式*/
  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 a
  15. {
  16. display:inline;
  17. }
  18. /*标签云的效果*/
  19. .home-item ul.tagcloud li.cloud-10 a
  20. {
  21. font-size:110%;
  22. }
  23. .home-item ul.tagcloud li.cloud-20 a
  24. {
  25. font-size:120%;
  26. }
  27. .home-item ul.tagcloud li.cloud-30 a
  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 a
  35. {
  36. font-size:190%;
  37. }
  38. .home-item ul.tagcloud li.cloud-100 a
  39. {
  40. font-size:200%;
  41. }
复制代码


本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

在Laravel中使用Flash会话数据 在Laravel中使用Flash会话数据 Mar 12, 2025 pm 05:08 PM

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

php中的卷曲:如何在REST API中使用PHP卷曲扩展 php中的卷曲:如何在REST API中使用PHP卷曲扩展 Mar 14, 2025 am 11:42 AM

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

简化的HTTP响应在Laravel测试中模拟了 简化的HTTP响应在Laravel测试中模拟了 Mar 12, 2025 pm 05:09 PM

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

在Codecanyon上的12个最佳PHP聊天脚本 在Codecanyon上的12个最佳PHP聊天脚本 Mar 13, 2025 pm 12:08 PM

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

解释PHP中晚期静态结合的概念。 解释PHP中晚期静态结合的概念。 Mar 21, 2025 pm 01:33 PM

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸

自定义/扩展框架:如何添加自定义功能。 自定义/扩展框架:如何添加自定义功能。 Mar 28, 2025 pm 05:12 PM

本文讨论了将自定义功能添加到框架上,专注于理解体系结构,识别扩展点以及集成和调试的最佳实践。

如何用PHP的cURL库发送包含JSON数据的POST请求? 如何用PHP的cURL库发送包含JSON数据的POST请求? Apr 01, 2025 pm 03:12 PM

使用PHP的cURL库发送JSON数据在PHP开发中,经常需要与外部API进行交互,其中一种常见的方式是使用cURL库发送POST�...

See all articles