默认情况下的输出内容:
- smallest —— 最小的标签(使用次数最少)显示大小为8
- largest ——最大的标签(使用次数最多)显示大小为22
- unit —— 最大值最小值的单位为'pt'
- number —— 至多显示45个标签
- format —— 以平面形式显示所有标签(标签之间用空格隔开)
- separator —— 显示标签之间的空格
- orderby —— 按名称为标签排序
- order —— 以升序排列
- exclude —— 不排除任何标签
- include —— 包括所有标签
- topic_count_text_callback —— 使用函数 default_topic_count_text
- link —— 可视
- taxonomy —— 用文章的标签作为云基础
- echo —— 输出结果
但由于该方法把样式集合到了里面,使用起来不怎么友好,如果想自定义读取标签并修改展示样式该怎么做呢,那也是非常简单的,看代码实例,这里根据get_tags来获取:
$html = '<ul class="post_tags">'; foreach (get_tags( array('number' => 50, 'orderby' => 'count', 'order' => 'DESC', 'hide_empty' => false) ) as $tag){ $color = dechex(rand(0,16777215)); $tag_link = get_tag_link($tag->term_id); $html .= "<li><a title='{$tag->name} Tag' class='{$tag->slug}' style='color:#{$color}'>"; $html .= "{$tag->name} ({$tag->count})</a></li>"; } $html .= '</ul>'; echo $html;
如果要求随机获取标签在首页显示,那可以使用以下代码,但这种做法貌似不利于seo,可得慎重使用
//获取随机标签 function get_rand_tags() { global $post, $wpdb; $sql = "SELECT * FROM {$wpdb->prefix}terms wt INNER JOIN {$wpdb->prefix}term_taxonomy wtt on wt.term_id=wtt.term_id where wtt.taxonomy='post_tag' ORDER BY RAND() LIMIT 20"; $related_posts = $wpdb->get_results($sql); $html = '<ul class="post_tags">'; foreach($related_posts as $tag) { $color = dechex(rand(0,16777215)); $tag_link = get_tag_link($tag->term_id); $html .= "<li><a target='_blank' title='{$tag->name} Tag' class='{$tag->slug}' style='color:#{$color}'>"; $html .= "{$tag->name} ({$tag->count})</a></li>"; } $html .= '</ul>'; echo $html; }
获取随机标签用get_tags
函数怎么变化参数都是没法获取到的(反正我是获取不到,欢迎大神留言指导),结果最后就用的sql连接表查询就搞出来了。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
标签:WordPress
相关阅读 >>
使用cdn和ajax加速wordpress中jquery的加载
输出wordpress数据库查询的具体内容 减少数据库查询次数
wordpress如何设置文章置顶以及区分置顶文章与普通文章
wordpress 相册插件 nextgen-gallery 添加目录将中文转为拼音的解决办法
更多相关阅读请进入《wordpress》频道 >>