随机标签

燃烧的冰2021-11-02  3.7K+

全站随机 tag ,仅查询最新创建的500个,不建议超过5000。可以放在任意地方,具体怎么发挥看大家了。样式 bootstrap 自行修改。

<?php if ('mysql' == $conf['cache']['type']) {
   $taglist = well_tag_find(1, 500);
} else {
   $taglist = cache_get('well-taglist-random');
   if (NULL === $taglist) {
      $taglist = well_tag_find(1, 500);
      $taglist and cache_set('well-taglist-random', $taglist, 1800);
   }
}
?>
<?php if($taglist){
$tagkeys = array_keys($taglist);
$tagtotal = count($tagkeys) > 20 ? 20 : count($tagkeys);
$randkeys = count($tagkeys) > 20 ? array_rand($tagkeys, $tagtotal) : $tagkeys;
?>
<div class="card border-0 rounded shadow-sm mb-3">
    <div class="card-header border-0 rounded-top bg-white">
        <h3 class="h6 font-weight-400 my-0">
            热门标签
        </h3>
    </div>

    <ul class="list-unstyled right-font d-flex flex-wrap bg-white px-3 py-2 m-0">
        <!-- 循环输出 tag 开始 -->
        <?php foreach($taglist as $val) { ?>
        <?php if (!in_array($val['tagid'], $randkeys)) continue; ?>
        <li class="px-2 py-1 badge-pill badge-light right-tag mr-2 mb-2">
            <h4 class="h6 my-0">
                <!-- 链接和 tag -->
                <a href="<?php echo $val['url'];?>" class="d-block text-truncate right-font">
                    <?php echo $val['name'];?>
                </a>
            </h4>
        </li>
        <?php } ?>
        <!-- 循环输出 tag 结束 -->

    </ul>
</div>
<?php } ?>
0