wordpress-theme-puock icon indicating copy to clipboard operation
wordpress-theme-puock copied to clipboard

标签云的标签随机出现

Open zhanggaoxuan opened this issue 2 years ago • 3 comments

是否为已有功能:是 建议阐述:

目前标签云排序规律好像没有,所以出现的标签都是固定的,建议允许随机出现

zhanggaoxuan avatar May 15 '22 06:05 zhanggaoxuan

确实需要这个功能

blblank avatar Jun 14 '22 03:06 blblank

随机出现,或者根据使用频次,有突出重点的显示

luteresa avatar Jul 19 '22 09:07 luteresa

目前应该是按类似字母顺序排序的,实际调用了get_tags()函数:https://developer.wordpress.org/reference/functions/get_tags/

个人的两点建议供参考: 1、可以开发根据频次排序的tags列表 2、如果有网页缓存,标签随机出现的意义不大,不利于寻找标签啊。

有两个思路实现: a. 前端获取到标签列表,进行随机处理,不会受网页缓存的影响 b.修改/wordpress-theme-puock-2.6.2/inc/fun/widget.php, 用shuffle函数进行随机处理, 该文件785行附近

    function widget( $args, $instance ){
        $this->get_common_widget_header($instance);
        echo '<div class="widget-puock-tag-cloud">';
        $tags = pk_cache_get(PKC_WIDGET_TAGS);
        if(!$tags){
            $tags = get_tags();
            pk_cache_set(PKC_WIDGET_TAGS,$tags);
        }
        $max_count = $this->get_num_val($instance, 'max_count');
        if(count($tags) > 0){
            $count = 0;
            shuffle($tags);
            foreach ($tags as $tag){
                if ($max_count > 0 && $count >= $max_count){
                    break;
                }

rankment avatar Sep 28 '22 14:09 rankment