帝国cms 在终极栏目页基于副表infotags实现当前栏目TAGS调用

分类栏目:经验 - WEB前端

发布于 暂无评论

infotags是TAG的字段,是用来实现栏目的信息快捷分类的,是碎片化的概念,它是面向用户的,一般来说它的词要比关键字keyboard的要短,甚至是不一样的词。
keyboard是页面关键字的字段,从优化的角度来说,把这关键字的词也弄得很短的话,根本对优化没什么效果。

那么问题就来了,很多人把infotags和keyboard的作用分不清,都把keyboard当作infotags来用,导致keyboard字段填写的信息和TAG的一样,这样的话对信息分类或用户体验或优化都是不利的。

系统目前还没有可调用当前栏目的TAGS列表的功能,我自己查了很多资料,还拿了论坛的一个网友的代码改了改,做成的

注意:是查询副表TASS字段infotags 的哟。并非是keyboard字段的。

1.添加函数到userfun.php

function user_show_classtags($tbname,$classid,$num){
                global $empire,$dbtbpre;

                if (empty($tbname)){
                        $tbname="news";
                }

                if (!empty($classid)){
                        $where=" where classid=".$classid;
                }else{
                        $where="";
                }


                $sql=$empire->query("select infotags from {$dbtbpre}ecms_{$tbname}_data_1".$where);

                while ($r = $empire->fetch ($sql)){
                        if ($r[infotags]){
                                $infotags.=','.$r[infotags];
                        }
                }

                $infotags=trim($infotags,',');
                $array=explode(',',$infotags);
                $count=array_count_values($array);
                arsort($count,SORT_NUMERIC);
                foreach($count as $key=>$val){
                $string=$string.$key.",";
                }
                $string=trim($string,',');
                $tagstring=explode(',',$string);

                if($num<=count($tagstring)){
                        $tagsnum=$num;
                }else{
                        $tagsnum=count($tagstring);
                }

                for ($j=0;$j<$tagsnum;$j++){
                echo "<li><a href=/e/tags/?tagname=".$tagstring[$j].">".$tagstring[$j]."</a></li>";
                }

        }

2.添加标签

标签名:当前栏目TAGS
标签符号:showtagsclas
函数名:user_show_classtags
标签格式:[showtagsclas]数据表名,栏目ID,TAGS条数[/showtagsclas]
标签说明:随便写

3.调用方法

例子:[showtagsclas]download,$class_r[$GLOBALS[navclassid]][classid],30[/showtagsclas]