• 使dedecms的list标签支持多字段排序


    织梦list标签的orderby属性只支持按一个字段排序,如果想多字段排序的话,我对后台的PHP进行了修改,使其可以支持多字段排序,修改如下:

    先找到文件arc.listview.class.php 在主目录include文件夹下,找到

     //如果不用默认的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 `#@__archives` arc
               LEFT JOIN `#@__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 `#@__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 `#@__archives` arc LEFT JOIN `#@__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 `#@__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 `#@__archives` arc LEFT JOIN `#@__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 `#@__archives` arc
               LEFT JOIN `#@__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'} 

  • 相关阅读:
    ZJOI 2014 星系调查(推导)
    APIO 2014 回文串(Manacher+后缀自动机+倍增)
    HDU 3948 The Number of Palindromes(Manacher+后缀数组)
    BalkanOI 2018 Parentrises(贪心+DP)
    POJ 3693 Maximum repetition substring(后缀数组+ST表)
    HDU 5769 Substring(后缀数组)
    POJ 1743 Musical Theme(后缀数组+二分答案)
    POJ 3261 Milk Patterns(后缀数组+二分答案)
    THUSCH 2017 大魔法师(矩阵乘法+线段树)
    BZOJ 2759 一个动态树好题(动态树)
  • 原文地址:https://www.cnblogs.com/Byrd/p/2178348.html
Copyright © 2020-2023  润新知