2020-12-16 13:38发布
wordpress如何在首页及文章页调用随机的tag标签
//获取随机标签
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
->get_results(
);
$html
''
foreach
(
as
$tag
)
$color
dechex
(rand(0,16777215));
$tag_link
= get_tag_link(
->term_id);
.=
"name} Tag' class='{$tag->slug}' style='color:#{$color}'>"
"{$tag->name} ({$tag->count})"
}
echo
最多设置5个标签!
//获取随机标签
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
.=
"name} Tag' class='{$tag->slug}' style='color:#{$color}'>"
;
$html
.=
"{$tag->name} ({$tag->count})"
;
}
$html
.=
''
;
echo
$html
;
}
一周热门 更多>