//获取随机标签
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 href='{$tag_link}' 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连接表查询就搞出来了。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对黑区网络的支持。如果你想了解更多相关内容请查看下面相关链接
