我们在发布文章的时候会给文章添加一些标签,来对文章进行分类以及管理,对于一个标签,到底有多少文章使用了这个标签是可以输出的,不过需要费一番周折。 第一步:首先在你的functions中添加如下代码:
//<span class="tag-span"><a class="tag" href="http://liuronghuan.com/tag/%e6%a0%87%e7%ad%be%e4%ba%91" title="View all posts in 标签云" target="_blank">标签云</a></span>输出文章数量 function Tagno($text) { $text = preg_replace_callback('|<a (.+?)</a>|i', 'tagnoCallback', $text); return $text; } function tagnoCallback($matches) { $text=$matches[1]; preg_match('|title=(.+?)style|i',$text ,$a); preg_match("/[0-9]+/",$a[1],$a); return "<a ".$text ."<span>(".$a[0].")</span></a>"; } add_filter('wp_tag_cloud', 'Tagno', 1);
第二步:然后在需要显示标签云的地方调用如下代码:
<?php wp_tag_cloud('unit=px&smallest=14&largest=14&number=30&orderby=count&order=DESC'); ?>
里面的大致意思是:最大字体以及最小字体都是14PX,显示30个标签,根据使用文章数量的多少降序排列 效果如本站右侧显示!