当前位置:首页 > 教程中心 > CMS教程 > DedeCMS

DEDECMS给list标签加上多字段排序功能

所属栏目:DedeCMS 时间:2013-12-13 来源:网络 作者:不详 点击:

dedecms的list标签orderby属性只支持按一个字段排序,假如想多个字段排序的话,就需要对PHP举办修改,使其可以支持多字段排序,修改如下:

打开include/arc.listview.class.php,找到:

//假如不消默认的sortrank或id排序,利用连系查询(数据量大时很是迟钝) 
       if(preg_match('/hot|click|lastpost|title/', $orderby)) 
       { 
           $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname, 
          tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath 
          $addField
          FROM `js_archives` arc 
          LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id 
          $addJoin
          WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row"; 
       } 
       //普通环境先从arctiny表查出ID,然后按ID查询(速度很是快) 
       else
       { 
           $t1 = ExecTime(); 
           $ids = array(); 
           $query = "SELECT id FROM `js_arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row "; 
           $this->dsql->SetQuery($query); 
           $this->dsql->Execute(); 
           while($arr=$this->dsql->GetArray()) 
           { 
               $ids[] = $arr['id']; 
           } 
           $idstr = join(',',$ids); 
           if($idstr=='') 
           { 
               return ''; 
           } 
           else
           { 
               $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname, 
                      tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath 
                      $addField
                      FROM `js_archives` arc LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id 
                      $addJoin
                      WHERE arc.id in($idstr) $ordersql "; 
           } 
           $t2 = ExecTime(); 
           //echo $t2-$t1; 
  
       }

替换为:

if($orderby=="default") 
       { 
           $t1 = ExecTime(); 
           $ids = array(); 
           $query = "SELECT id FROM `js_arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row "; 
           $this->dsql->SetQuery($query); 
           $this->dsql->Execute(); 
           while($arr=$this->dsql->GetArray()) 
           { 
               $ids[] = $arr['id']; 
           } 
           $idstr = join(',',$ids); 
           if($idstr=='') 
           { 
               return ''; 
           } 
           else
           { 
               $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname, 
                      tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath 
                      $addField
                      FROM `js_archives` arc LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id 
                      $addJoin
                      WHERE arc.id in($idstr) $ordersql "; 
           } 
           $t2 = ExecTime(); 
           //echo $t2-$t1; 
  
       } 
        else
       { 
           $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname, 
          tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath 
          $addField
          FROM `js_archives` arc 
          LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id 
          $addJoin
          WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row"; 
       }

找到:

else { 
            $ordersql=" ORDER BY arc.sortrank $orderWay"; 
      }

替换为:

else if($orderby=="default"){ 
            $ordersql=" ORDER BY arc.sortrank $orderWay"; 
        } 
        else{ 
           $ordersql=" ORDER BY ".$orderby.",arc.sortrank $orderWay"; 
        }

此刻在模板中就可以应用了多字段排序了,模板应用如下:

{dede:list pagesize='17' orderby='arc.title desc,arc.id'}


请站长喝杯咖啡?

站长一直坚持白天工作、晚上熬夜更新素材,付出了巨大的精力和时间,其中的辛酸难以言述。

坚持免积分、免登录、无任何限制下载!如果本站素材对你有用,不妨考虑请站长喝杯咖啡鼓励一下!

标签:

你应该也喜欢这些吧

共有 0 条评论

给个评价吧

验证码: