自定义dedecms栏目的排列顺序

前端首页模板部分代码(添加了myorder="typename"):

<ul>
<li><a href="{dede:global.cfg_cmsurl/}" target="_self">首页</a></li>
{dede:channel myorder="typename" type="top" row="8"}
<li><a href="[field:typeurl/]" title="[field:typename/]" target="_self">
[field:typename/]
</a></li>
{/dede:channel}
</ul>


修改include\taglib\channel.lib.php,将以下代码:

if($type=='top')
    {
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
          From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line ";
    }
    else if($type=='son')
    {
        if($typeid==0) return '';
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
          From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by sortrank asc limit 0, $line ";
    }
    else if($type=='self')
    {
        if($reid==0) return '';
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
            FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
    }
    //And id<>'$typeid'
    $needRel = false;
    $dtp2 = new DedeTagParse();
    $dtp2->SetNameSpace('field','[',']');
    $dtp2->LoadSource($innertext);
    //检查是否有子栏目,并返回rel提示(用于二级菜单)
    if(preg_match('#:rel#', $innertext)) $needRel = true;
    
    if(empty($sql)) return '';
    $dsql->SetQuery($sql);
    $dsql->Execute();
    
    $totalRow = $dsql->GetTotalRow();
    //如果用子栏目模式,当没有子栏目时显示同级栏目
    if($type=='son' && $reid!=0 && $totalRow==0)
    {
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
            FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
        $dsql->SetQuery($sql);
      $dsql->Execute();
    }

改为:

$myorder=$ctag->CAttribute->Items["myorder"];
    if(empty($myorder)){
        $sortrank="sortrank";
    }else{
        $sortrank=$myorder;
    }
    if($type=='top')
    {
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
          From `#@__arctype` WHERE reid=0 And ishidden<>1 order by $sortrank asc limit 0, $line ";
    }
    else if($type=='son')
    {
        if($typeid==0) return '';
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
          From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by $sortrank asc limit 0, $line ";
    }
    else if($type=='self')
    {
        if($reid==0) return '';
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
            FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by $sortrank asc limit 0, $line ";
    }
    //And id<>'$typeid'
    $needRel = false;
    $dtp2 = new DedeTagParse();
    $dtp2->SetNameSpace('field','[',']');
    $dtp2->LoadSource($innertext);
    //检查是否有子栏目,并返回rel提示(用于二级菜单)
    if(preg_match('#:rel#', $innertext)) $needRel = true;


    if(empty($sql)) return '';
    $dsql->SetQuery($sql);
    $dsql->Execute();


    $totalRow = $dsql->GetTotalRow();
    //如果用子栏目模式,当没有子栏目时显示同级栏目
    if($type=='son' && $reid!=0 && $totalRow==0)
    {
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
            FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by $sortrank asc limit 0, $line ";
        $dsql->SetQuery($sql);
        $dsql->Execute();
    }

至于详细内容,建议学习【韩顺平主讲织梦dedecms 5.7二次开发实战仿站模板制作教程】

你可能感兴趣的:(自定义dedecms栏目的排列顺序)