wp如何调用随机的tag标签

2020-12-16 13:38发布

wordpress如何在首页及文章页调用随机的tag标签

1条回答
taoge
1楼-- · 2021-03-05 17:29
//获取随机标签
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 = '
 foreach($related_posts as $tag)
 {
 $color = dechex(rand(0,16777215));
 $tag_link = get_tag_link($tag->term_id);
 }
 $html .= '';
 echo $html;
}


一周热门 更多>