level 1
the_category()函数可以获取到当前文章所属分类的一个数组集合,那么,怎么从这个数组中随机输出一个,不是输出第一个分类,是随机的。
2019年07月22日 18点07分
2
level 7
<?php
$categorys=get_the_category();
$category_end_index= count($categorys) -1;
echo $categorys[rand(0, $category_end_index]->name;
?>
不谢!
2019年07月23日 04点07分
4