标签云是很多wordpress主题都有的一个主题元素,上一篇wordpress教程中,我们已经向大家介绍了的方法。很多站长在的过程中,想要给主题添加彩色标签云功能,包括边栏调用和页面调用,今天我们就向大家介绍一下实现的方法。
我们可以使用 wp_tag_cloud() 函数实现标签云的调用。比如下面的样例:
Crayon-5c891cc245e07970312099" class="
Crayon-
Syntax Crayon-theme-classic
Crayon-font-monaco
Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mou
SEOver" style=" margin-top: 12px; margin-b
ottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mou
SEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-title">Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-mixed-highlight" title="Contains Mixed Languages">Crayon-button
Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button
Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button
Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button
Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button
Crayon-
copy-button" title="
copy">
Crayon-button-icon">
Crayon-button
Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHPCrayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-main" style="">
Crayon-table">Crayon-row">Crayon-nums " data-settings="show">Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line=" Crayon-5c891cc245e07970312099-1">1 | Crayon-code">Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-
tab-size:4; -o-
tab-size:4; -webkit-
tab-size:4;
tab-size:4;">
Crayon-line" id="
Crayon-5c891cc245e07970312099-1">
Crayon-ta">PHPCrayon-h"> Crayon-e">wp_tag_cloudCrayon-sy">(Crayon-s">'smallest=12&largest=18&unit=px&number=0&orderby=count&order=DESC'Crayon-sy">)Crayon-sy">;代码注释:
smallest表示标签的最小字号
largest表示最大字号
unit=px表示字体使用像素单位
number=0表示显示所有标签,如果为40,表示显示40个
orderby=count表示按照标签所关联的文章数来排列
order=DESC表示降序排序(ASC表示升序排序,DESC表示降序排序)
根据上面的参数,您已经可以调用标签云了,切换到主题目录,打开 functions.PHP 文件,加入以下代码即可实现彩色标签云功能:
Crayon-5c891cc245e11418149858" class="
Crayon-
Syntax Crayon-theme-classic
Crayon-font-monaco
Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mou
SEOver" style=" margin-top: 12px; margin-b
ottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mou
SEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-title">functions.PHPCrayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button
Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button
Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button
Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button
Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button
Crayon-
copy-button" title="
copy">
Crayon-button-icon">
Crayon-button
Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHPCrayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-main" style="">
Crayon-table">Crayon-row">Crayon-nums " data-settings="show">Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line=" Crayon-5c891cc245e11418149858-1">1 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e11418149858-2">2 Crayon-num" data-line=" Crayon-5c891cc245e11418149858-3">3 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e11418149858-4">4 Crayon-num" data-line=" Crayon-5c891cc245e11418149858-5">5 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e11418149858-6">6 Crayon-num" data-line=" Crayon-5c891cc245e11418149858-7">7 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e11418149858-8">8 Crayon-num" data-line=" Crayon-5c891cc245e11418149858-9">9 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e11418149858-10">10 Crayon-num" data-line=" Crayon-5c891cc245e11418149858-11">11 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e11418149858-12">12 Crayon-num" data-line=" Crayon-5c891cc245e11418149858-13">13 | Crayon-code">Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-
tab-size:4; -o-
tab-size:4; -webkit-
tab-size:4;
tab-size:4;">
Crayon-line" id="
Crayon-5c891cc245e11418149858-1">
Crayon-c">//边栏彩色标签Crayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e11418149858-2">
Crayon-t">functionCrayon-h"> Crayon-e">colorCloudCrayon-sy">(Crayon-v">$textCrayon-sy">)Crayon-h"> Crayon-sy">{Crayon-line" id="
Crayon-5c891cc245e11418149858-3">
Crayon-h"> Crayon-v">$textCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">preg_replace_callbackCrayon-sy">(Crayon-s">'||i'Crayon-sy">,Crayon-s">'colorCloudCallback'Crayon-sy">,Crayon-h"> Crayon-v">$textCrayon-sy">)Crayon-sy">;Crayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e11418149858-4">
Crayon-h"> Crayon-k ">returnCrayon-h"> Crayon-v">$textCrayon-sy">;Crayon-line" id="
Crayon-5c891cc245e11418149858-5">
Crayon-sy">}Crayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e11418149858-6">
Crayon-t">functionCrayon-h"> Crayon-e">colorCloudCallbackCrayon-sy">(Crayon-v">$matchesCrayon-sy">)Crayon-h"> Crayon-sy">{Crayon-line" id="
Crayon-5c891cc245e11418149858-7">
Crayon-h"> Crayon-v">$textCrayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$matchesCrayon-sy">[Crayon-cn">1Crayon-sy">]Crayon-sy">;Crayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e11418149858-8">
Crayon-h"> Crayon-v">$colorCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">dechexCrayon-sy">(Crayon-e">randCrayon-sy">(Crayon-cn">0Crayon-sy">,Crayon-cn">16777215Crayon-sy">)Crayon-sy">)Crayon-sy">;Crayon-line" id="
Crayon-5c891cc245e11418149858-9">
Crayon-h"> Crayon-v">$patternCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'/style=(\'|\”)(.*)(\'|\”)/i'Crayon-sy">;Crayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e11418149858-10">
Crayon-h"> Crayon-v">$textCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">preg_replaceCrayon-sy">(Crayon-v">$patternCrayon-sy">,Crayon-h"> Crayon-s">"style=\"color:#{$color};$2;\""Crayon-sy">,Crayon-h"> Crayon-v">$textCrayon-sy">)Crayon-sy">;Crayon-line" id="
Crayon-5c891cc245e11418149858-11">
Crayon-h"> Crayon-k ">returnCrayon-h"> Crayon-s">""Crayon-sy">;Crayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e11418149858-12">
Crayon-sy">}Crayon-line" id="
Crayon-5c891cc245e11418149858-13">
Crayon-e">add_filterCrayon-sy">(Crayon-s">'wp_tag_cloud'Crayon-sy">,Crayon-h"> Crayon-s">'colorCloud'Crayon-sy">,Crayon-h"> Crayon-cn">1Crayon-sy">)Crayon-sy">;1) 复制你主题的 page.PHP 文件,在该文件的顶部添加:
Crayon-5c891cc245e14788885519" class="
Crayon-
Syntax Crayon-theme-classic
Crayon-font-monaco
Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mou
SEOver" style=" margin-top: 12px; margin-b
ottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mou
SEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-title">page-tags.PHPCrayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-mixed-highlight" title="Contains Mixed Languages">Crayon-button
Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button
Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button
Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button
Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button
Crayon-
copy-button" title="
copy">
Crayon-button-icon">
Crayon-button
Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHPCrayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-main" style="">
Crayon-table">Crayon-row">Crayon-nums " data-settings="show">Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line=" Crayon-5c891cc245e14788885519-1">1 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e14788885519-2">2 Crayon-num" data-line=" Crayon-5c891cc245e14788885519-3">3 Crayon-num Crayon-striped-num" data-line=" Crayon-5c891cc245e14788885519-4">4 Crayon-num" data-line=" Crayon-5c891cc245e14788885519-5">5 | Crayon-code">Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-
tab-size:4; -o-
tab-size:4; -webkit-
tab-size:4;
tab-size:4;">
Crayon-line" id="
Crayon-5c891cc245e14788885519-1">
Crayon-ta">PHPCrayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e14788885519-2">
Crayon-c">/*Crayon-line" id="
Crayon-5c891cc245e14788885519-3">
Crayon-c">Template Name: TagsCrayon-line
Crayon-striped-line" id="
Crayon-5c891cc245e14788885519-4">
Crayon-c">*/Crayon-line" id="
Crayon-5c891cc245e14788885519-5">
2) 使用下面的代码替换page.PHP中的 the_content();
:
Crayon-5c891cc245e16478849262" class="
Crayon-
Syntax Crayon-theme-classic
Crayon-font-monaco
Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mou
SEOver" style=" margin-top: 12px; margin-b
ottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mou
SEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-title">page-tags.PHPCrayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-mixed-highlight" title="Contains Mixed Languages">Crayon-button
Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button
Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button
Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button
Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button
Crayon-
copy-button" title="
copy">
Crayon-button-icon">
Crayon-button
Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHPCrayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-main" style="">
Crayon-table">Crayon-row">Crayon-nums " data-settings="show">Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line=" Crayon-5c891cc245e16478849262-1">1 | Crayon-code">Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-
tab-size:4; -o-
tab-size:4; -webkit-
tab-size:4;
tab-size:4;">
Crayon-line" id="
Crayon-5c891cc245e16478849262-1">
Crayon-ta">PHPCrayon-h"> Crayon-e">wp_tag_cloudCrayon-sy">(Crayon-s">'smallest=12&largest=18&unit=px&number=0&orderby=count&order=DESC'Crayon-sy">)Crayon-sy">;3) 删除page.PHP中的某些不需要的功能,最后将该文件另存为 page-tags.PHP ,这样,一个标签云模板就做好了。
4) 访问 wordpress后台-页面-新建页面,页面名称随便填一下,在 页面属性 中,选择 tags 模板即可。
您可以使用下面的函数调用,具体的修改方法,就靠您自己折腾主题了:
Crayon-5c891cc245e17838471915" class="
Crayon-
Syntax Crayon-theme-classic
Crayon-font-monaco
Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mou
SEOver" style=" margin-top: 12px; margin-b
ottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mou
SEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-title">Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-mixed-highlight" title="Contains Mixed Languages">Crayon-button
Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button
Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button
Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button
Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button
Crayon-
copy-button" title="
copy">
Crayon-button-icon">
Crayon-button
Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHPCrayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-main" style="">
Crayon-table">Crayon-row">Crayon-nums " data-settings="show">Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line=" Crayon-5c891cc245e17838471915-1">1 | Crayon-code">Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-
tab-size:4; -o-
tab-size:4; -webkit-
tab-size:4;
tab-size:4;">
Crayon-line" id="
Crayon-5c891cc245e17838471915-1">
Crayon-ta">PHPCrayon-h"> Crayon-e">wp_tag_cloudCrayon-sy">(Crayon-s">'smallest=12&largest=18&unit=px&number=20'Crayon-sy">)Crayon-sy">;注:一般制作比较规范的wordpress主题,都支持 Widget小工具,您可以在 wordpress后台-外观-小工具 中查看是否支持 标签云小工具。
原文地址:https://www.jb51.cc/wordpress/238372.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。