感觉Wordpress自带标签云不太美观,而上次使用Simple Tags插件虽然方便,但却在IE9中显示异常,只好弃用。今天决定用直接修改代码方式来修改标签显示。
查了下,并不困难,只需要改函数wp_tag_cloud的几个参数即可。
位于”/public_html/wp-includes/category-template.php”,,Wordpress原始代码为:
function wp_tag_cloud( $args = ” ) {
$defaults = array(
‘smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,
‘format’ => ‘flat’, ‘separator’ => “\n”, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,
‘exclude’ => ”, ‘include’ => ”, ‘link’ => ‘view’, ‘taxonomy’ => ‘post_tag’, ‘echo’ => true
);
修改如下:
function wp_tag_cloud( $args = ” ) {
$defaults = array(
‘smallest’ => 6, ‘largest’ => 26, ‘unit’ => ‘pt’, ‘number’ => 66,
‘format’ => ‘flat’, ‘separator’ => “\n”, ‘orderby’ => ‘count’, ‘order’ => ‘DESC’,
‘exclude’ => ”, ‘include’ => ”, ‘link’ => ‘view’, ‘taxonomy’ => ‘post_tag’, ‘echo’ => true
);
smallest最小的标签字号,largest最大的标签字号。
‘separator’ => “\n”标签用空格分隔
orderby排序依据:name名称,count数量
order顺序:ASC升序、递增 DESC降序、递减
wordpress安装插件Simple Tags.学到两个缩写 Asc,ascending order升序 Desc,descending order降序
作者: xuexx 日期: 2012/07/22
这个递增与递减有些歧义,顺序指从开始到结束的顺序,但从开始到结束是从上到下还是从下到上,即上面还是下面是开始?目前的国际主流看法应该是视上面为开始,但这与人的生活经验与心理相反。
★Wordpress.org官网介绍函数wp_tag_cloud()
The wp_tag_cloud() function displays a list of tags in what is called a ‘tag cloud’, where the size of each tag is determined by how many times that particular tag has been assigned to posts.
函数wp_tag_cloud() 显示一个被叫做标签云的标签列表,在那里各个标签的大小由特定标签曾经被分配给帖子的数目来决定。
Default Usage默认用法
<?php $args = array(
‘smallest’ => 8, 标签最小字号
‘largest’ => 22, 标签最大字号
‘unit’ => ‘pt’, 标签字号大小单位
‘number’ => 45, 标签数目
‘format’ => ‘flat’,
‘separator’ => \\”\n\\“,标签分隔符
‘orderby’ => ‘name’, 标签以什么排序
‘order’ => ‘ASC’, 顺序
‘exclude’ => null,
‘include’ => null,
‘topic_count_text_callback’ => default_topic_count_text,
‘link’ => ‘view’,
‘taxonomy’ => ‘post_tag’,
‘echo’ => true ); ?>
separator – Displays whitespace between tags
exclude – Exclude no tags
include – Include all tags
format
(optional) Format of the cloud display.标签云显示格式
‘flat’ separated by whitespace defined by ‘separator’ parameter.flat被separator参数定义的空格分隔
‘list’ UL with a class of ‘wp-tag-cloud’
‘array’ returns the tag cloud as an array for use in PHP
Default: flat
separator
(optional) The text/space between tags.标签间的文本或空格
Default: ‘\n’ (whitespace) 默认值:空格
orderby
(optional) Order of the tags.标签的顺序
‘name’
‘count’
Default: name
order
(optional) Sort order.排序顺序
‘ASC’
‘DESC’
‘RAND’ tags are in a random order.
Default: ASC
Code is Poetry http://codex.wordpress.org/Function_Reference/wp_tag_cloud