织梦栏目列表分页优化使其更符合SEO!

发布时间:2021-01-07 作者:安阳博客网 所属分类:程序代码

织梦是一个经久不衰的建站CMS,他与帝国CMS共同组建了现有的庞大网站互联网,许多网站都是使用织梦建设或是经过二开建设而成的,然而在使用织梦建设网站的时候,经常会使用而栏目功能,随着内容的不断增加,自然需要将列表进行分页处理,然而熟悉网站优化的人会发现其实织梦的栏目列表分页对SEO并不友好,因此我们需要对其列表进行修改!

/**
     *  获取静态的分页列表
     *
     * @access    public
     * @param     string  $list_len  列表宽度
     * @param     string  $list_len  列表样式
     * @return    string
     */
    function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")
    {
        $prepage = $nextpage = '';
        $prepagenum = $this->PageNo-1;
        $nextpagenum = $this->PageNo+1;
        if($list_len=='' || preg_match("/[^0-9]/", $list_len))
        {
            $list_len=3;
        }
        $totalpage = ceil($this->TotalResult/$this->PageSize);
        if($totalpage<=1 && $this->TotalResult>0)
        {

            return "<li><span class="pageinfo">共 <strong>1</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>
";
        }
        if($this->TotalResult == 0)
        {
            return "<li><span class="pageinfo">共 <strong>0</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li>
";
        }
        $purl = $this->GetCurUrl();
        $maininfo = "<li><span class="pageinfo">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>
";
        $tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
        $tnamerule = preg_replace("/^(.*)//", '', $tnamerule);
		$typedir= ereg_replace('{cmspath}',$GLOBALS['cfg_cmspath'],$this->Fields['typedir']);//NEWS ADD
		$baseUrl = $GLOBALS['cfg_basehost'].ereg_replace('{cmspath}',$GLOBALS['cfg_cmspath'],$this->Fields['baseUrl']);
		$xg = "/";
        //获得上一页和主页的链接
        if($this->PageNo != 1){
			if($prepagenum==1){
				$prepage.="<li><a href="".$baseUrl.$typedir."/">上一页</a></li>
";
				}
				else
				{
					$prepage.="<li><a href="".$baseUrl.$typedir.$xg.str_replace("{page}",$prepagenum,$tnamerule)."">上一页</a></li>
";
					}
					$indexpage="<li><a href="".$baseUrl.$typedir."/">首页</a></li>
";
					}
					else
				{
            $indexpage="<li>首页</li>
";
        }

        //下一页,未页的链接
        if($this->PageNo!=$totalpage && $totalpage>1)
        {
            $nextpage.="<li><a href="".$baseUrl.$typedir.$xg.str_replace("{page}",$nextpagenum,$tnamerule)."">下一页</a></li>
";
            $endpage="<li><a href="".$baseUrl.$typedir.$xg.str_replace("{page}",$totalpage,$tnamerule)."">末页</a></li>
";
        }
        else
        {
            $endpage="<li>末页</li>
";
        }

        //option链接
        $optionlist = '';

        $optionlen = strlen($totalpage);
        $optionlen = $optionlen*12 + 18;
        if($optionlen < 36) $optionlen = 36;
        if($optionlen > 100) $optionlen = 100;
        $optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>
";
        for($mjj=1;$mjj<=$totalpage;$mjj++)
        {
            if($mjj==$this->PageNo)
            {
                $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>
";
            }
            else
            {
                $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>
";
            }
        }
        $optionlist .= "</select></li>
";

        //获得数字链接
		$ye="页";
        $listdd="";
        $total_list = $list_len * 2 + 1;
        if($this->PageNo >= $total_list)
        {
            $j = $this->PageNo-$list_len;
            $total_list = $this->PageNo+$list_len;
            if($total_list>$totalpage)
            {
                $total_list=$totalpage;
            }
        }
        else
        {
            $j=1;
            if($total_list>$totalpage)
            {
                $total_list=$totalpage;
            }
        }
        for($j;$j<=$total_list;$j++)
        {
            if($j==$this->PageNo)
            {
                $listdd.= "<li class="thisclass">$j</li>
";
            }
            else
            {
                if($j==1)
				{
					$listdd.="<li><a href="".$baseUrl.$typedir."/">".$j."</a></li>
";
					}
					else
					{
						$listdd.="<li><a title="第$j$ye" href="".$baseUrl.$typedir.$xg.str_replace("{page}",$j,$tnamerule)."">".$j."</a></li>
";
						}
            }
        }
        $plist = '';
        if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
        if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
        if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
        if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
        if(preg_match('/end/i', $listitem)) $plist .= $endpage;
        if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
        if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
        
        return $plist;
    }

    /**
     *  获取动态的分页列表
     *
     * @access    public
     * @param     string  $list_len  列表宽度
     * @param     string  $list_len  列表样式
     * @return    string
     */
    function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
    {
        global $cfg_rewrite;
        $prepage = $nextpage = '';
        $prepagenum = $this->PageNo-1;
        $nextpagenum = $this->PageNo+1;
        if($list_len=='' || preg_match("/[^0-9]/", $list_len))
        {
            $list_len=3;
        }
        $totalpage = ceil($this->TotalResult/$this->PageSize);
        if($totalpage<=1 && $this->TotalResult>0)
        {
            return "<li><span class="pageinfo">共 1 页/".$this->TotalResult." 条记录</span></li>
";
        }
        if($this->TotalResult == 0)
        {
            return "<li><span class="pageinfo">共 0 页/".$this->TotalResult." 条记录</span></li>
";
        }
        $maininfo = "<li><span class="pageinfo">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li>
";
        
        $purl = $this->GetCurUrl();
        // 如果开启为静态,则对规则进行替换
        if($cfg_rewrite == 'Y')
        {
            $nowurls = preg_replace("/-/", ".php?", $purl);
            $nowurls = explode("?", $nowurls);
            $purl = $nowurls[0];
        }

        $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
        $purl .= '?'.$geturl;
        
        $optionlist = '';
        //$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>
";
        //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>
";

        //获得上一页和下一页的链接
        if($this->PageNo != 1)
        {
            $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>
";
            $indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>
";
        }
        else
        {
            $indexpage="<li><a>首页</a></li>
";
        }
        if($this->PageNo!=$totalpage && $totalpage>1)
        {
            $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>
";
            $endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>
";
        }
        else
        {
            $endpage="<li><a>末页</a></li>
";
        }


        //获得数字链接
        $listdd="";
        $total_list = $list_len * 2 + 1;
        if($this->PageNo >= $total_list)
        {
            $j = $this->PageNo-$list_len;
            $total_list = $this->PageNo+$list_len;
            if($total_list>$totalpage)
            {
                $total_list=$totalpage;
            }
        }
        else
        {
            $j=1;
            if($total_list>$totalpage)
            {
                $total_list=$totalpage;
            }
        }
        for($j;$j<=$total_list;$j++)
        {
            if($j==$this->PageNo)
            {
                $listdd.= "<li class="thisclass"><a>$j</a></li>
";
            }
            else
            {
                $listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>
";
            }
        }

        $plist = '';
        if(preg_match('/index/i', $listitem)) $plist .= $indexpage;
        if(preg_match('/pre/i', $listitem)) $plist .= $prepage;
        if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;
        if(preg_match('/next/i', $listitem)) $plist .= $nextpage;
        if(preg_match('/end/i', $listitem)) $plist .= $endpage;
        if(preg_match('/option/i', $listitem)) $plist .= $optionlist;
        if(preg_match('/info/i', $listitem)) $plist .= $maininfo;
        
        if($cfg_rewrite == 'Y')
        {
            $plist = str_replace('.php?tid=', '-', $plist);
            $plist = str_replace('&TotalResult=', '-', $plist);
            $plist = preg_replace("/&PageNo=(d+)/i",'-\1.html',$plist);
        }
        return $plist;
    }

修改需要涉及织梦核心文件,该文件名称为arc.listview.class.php,位置在根目录下的include文件夹当中,使用DW等专业代码编辑器进行编辑,将以下代码与之原有代码替换

保存后重新生成静态文件,再次打开列表页会发现分页变得非常符合SEO要求,这样在优化的时候就不会出现权重分散的情况发生.