【Ripro美化】圆角标签云的彩色背景效果实现纯粹的代码 - 汇站网

【Ripro美化】圆角标签云的彩色背景效果实现纯粹的代码

2021-04-28 0 1,035

为我们的文章添上点睛之笔,若能令标签云随机绽放出斑斓色彩,无疑将个性化魅力倍增。如今,我们摒弃繁琐插件,亲力亲为,以代码编织独一无二的彩色标签云。

教程指引

请将以下代码巧妙地融入您子主题的functions.php文件中,其路径为:您的域名/wp-content/themes/ripro/functions.php。

代码展示

在此,我们精选了一款既简洁又高效的代码示例,当然,您也可以在网络海洋中探寻更多选择。只需将这段代码优雅地安置在子主题 functions.php 的尾声处,即可轻松实现。


# 汇站网
# https://www.huizhanii.com/76.html
<span class="token comment">/***圆角背景色标签 - ZTmbk.com***/</span>
<span class="token keyword keyword-function">function</span> <span class="token function">colorCloud</span><span class="token punctuation">(</span><span class="token variable">$text</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
<span class="token variable">$text</span> <span class="token operator">=</span> <span class="token function">preg_replace_callback</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'|&lt;a (.+?)&gt;|i'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'colorCloudCallback'</span><span class="token punctuation">,</span> <span class="token variable">$text</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token keyword keyword-return">return</span> <span class="token variable">$text</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span> 
<span class="token keyword keyword-function">function</span> <span class="token function">colorCloudCallback</span><span class="token punctuation">(</span><span class="token variable">$matches</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> 
<span class="token variable">$text</span> <span class="token operator">=</span> <span class="token variable">$matches</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span> 
<span class="token variable">$colors</span> <span class="token operator">=</span> <span class="token keyword keyword-array">array</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'48D1CC'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'a26ff9'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'fb7da9'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'666'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'19B5FE'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'ff5e5c'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'ffbb50'</span><span class="token punctuation">,</span><span class="token single-quoted-string string">'1ac756'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token variable">$color</span><span class="token operator">=</span><span class="token variable">$colors</span><span class="token punctuation">[</span><span class="token function">dechex</span><span class="token punctuation">(</span><span class="token function">rand</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">;</span> 
<span class="token variable">$pattern</span> <span class="token operator">=</span> <span class="token single-quoted-string string">'/style=(\'|\")(.*)(\'|\")/i'</span><span class="token punctuation">;</span> 
<span class="token variable">$text</span> <span class="token operator">=</span> <span class="token function">preg_replace</span><span class="token punctuation">(</span><span class="token variable">$pattern</span><span class="token punctuation">,</span> <span class="token double-quoted-string string">"style=\"display: inline-block; *display: inline; *zoom: 1; color: #fff; padding: 6px 6px; margin: 0 5px 5px 0; background-color: #<span class="token interpolation"><span class="token punctuation">{</span><span class="token variable">$color</span><span class="token punctuation">}</span></span>; border-radius: 5px; -webkit-transition: background-color .4s linear; -moz-transition: background-color .4s linear; transition: background-color .4s linear;\""</span><span class="token punctuation">,</span> <span class="token variable">$text</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token variable">$pattern</span> <span class="token operator">=</span> <span class="token single-quoted-string string">'/style=(\'|\")(.*)(\'|\")/i'</span><span class="token punctuation">;</span> 
<span class="token keyword keyword-return">return</span> <span class="token double-quoted-string string">"&lt;a <span class="token interpolation"><span class="token variable">$text</span></span>&gt;"</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span> 
<span class="token function">add_filter</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'wp_tag_cloud'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'colorCloud'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

转载请注明:汇站网 » 【Ripro 美化】圆角标签云的彩色背景效果实现纯粹的代码

收藏 (0)

微信扫一扫

支付宝扫一扫

点赞 (0)

免责 声明

本资源仅用于个人 学习和研究使用,禁止用于任何商业环境!

 1.  本网站名称:汇站网
 2.  本站永久网址:https://www.huizhanii.com/
 3.  本站所有资源来源于网友投稿和高价 购买,所有资源仅对编程人员及源代码爱好者开放下载做参考和研究及学习,本站不提供任何技术服务 !
 4.  本站所有资源的展示图片和信息不代表本站的立场 !本站只是储蓄平台及搬运
 5.  下载者禁止在服务器和虚拟机下进行搭建运营,本站 所有资源不支持联网运行!只允许调试,参考和研究!!!!
 6.  未经原版权作者许可,禁止用于任何 商业环境,任何人不得擅作它用,下载者不得用于违反国家法律,否则发生的一切法律后果自行承担!
 7.  为尊重作者版权,请在下载24小时 内删除!请购买原版授权作品,支持你喜欢的作者,谢谢!
 8.  若资源侵犯了您的合法权益, 请持 您的版权证书和相关原作品信息来信通知我们请来信     通知我们 我们会及时删除,给您带来的不便,我们深表歉意!
 9.  如下载链接失效、广告或者压缩包 问题请联系站长处理!
 10.  如果你也有好源码或者教程,可以 发布到网站,分享有金币奖励和额外收入!
 11.  本站资源售价只是赞助,收取费用 仅维持本站的日常运营所需!
 12.  因源码具有可复制性,一经赞助 ,不得以任何形式退款。
 13.  更多详情请点击查看

汇站网 WordPress 【Ripro美化】圆角标签云的彩色背景效果实现纯粹的代码 https://www.huizhanii.com/76.html

汇站

站长资源下载中心-找源码上汇站

常见问题
  • 如果付款后没有弹出下载页面,多刷新几下,有问题联系客服!
查看详情
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
查看详情

相关文章

发表评论
暂无评论
  随机评论   表情   下载本站到电脑桌面


表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情
登录后评论
联系官方客服

为您解决烦忧 - 24小时在线 专业服务

(汇站网)一个专注站长资源的平台网站,提供最新的网站模板和整站源码,内容包含各类精品网页模板,企业网站模板,网站模板,DIV+CSS模板,织梦模板,帝国cms模板,discuz模板,wordpress模板,个人博客论坛模板,上千种免费网页模板下载尽在汇站网.找源码上汇站.huizhanii.com