dede文章系统tag标签伪静态方法by piikee

此为伪静态需要修改三个php文件,分别是/include/arc.taglist.class.php ,/include/taglib/tag.lib.php,tags.php,还有一个伪静态文件。

/include/arc.taglist.class.php

GetPageListDM函数整个替换为下面函数

/**
* 获取动态的分页列表
*
* @access public
* @param int $list_len 列表宽度
* @param string $listitem 列表样式
* @return string
*/

function GetPageListDM($list_len,$listitem=”info,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 = $this->TotalPage;
if($totalpage <= 1 && $this->TotalResult > 0)
{
return “<span class=\”pageinfo\”>共1页/”.$this->TotalResult.”条</span>”;

}
if($this->TotalResult == 0)
{
return “<span class=\”pageinfo\”>共0页/”.$this->TotalResult.”条</span>”;
}
$maininfo = “<span class=\”pageinfo\”>共{$totalpage}页/”.$this->TotalResult.”条</span>”;
$purl = $this->GetCurUrl();
$basename = basename($purl);
$tmpname = explode(‘.’, $basename);

$purl = str_replace($basename, ”, $purl).urlencode($this->Tag);
//var_dump($purl);exit;
//$purl .= “?/”.urlencode($this->Tag);

//获得上一页和下一页的链接
if($this->PageNo != 1)
{
if($this->PageNo==2)//edit by piikee

$prepage.=”<li><a href='”.$this->TagInfos[‘id’].”.html’>上一页</a></li>”;//edit by piikee
else
$prepage.=”<li><a href='”.$this->TagInfos[‘id’].”_”.$prepagenum.”.html’>上一页</a></li>”;//edit by piikee

$indexpage=”<li><a href='”.$this->TagInfos[‘id’].”.html’>首页</a></li>”;//edit by piikee
}
else
{
$indexpage=”<li><a>首页</a></li>”;
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.=”<li><a href='”.$this->TagInfos[‘id’].”_$nextpagenum.html’>下一页</a></li>”;//edit by piikee
$endpage=”<li><a href='”.$this->TagInfos[‘id’].”_$totalpage.html’>末页</a></li>”;//edit by piikee
}
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 if($j==1)//edit by piikee
{
$listdd.=”<li><a href='”.$this->TagInfos[‘id’].”.html’>”.$j.”</a></li>”;//edit by piikee
}
else
{
$listdd.=”<li><a href='”.$this->TagInfos[‘id’].”_$j.html’>”.$j.”</a></li>”;//edit by piikee
}
}
$plist = ”;
if(preg_match(‘/info/i’, $listitem))
{
$plist .= $maininfo.’ ‘;
}
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.’ ‘;
}
return $plist;
}

 

/include/taglib/tag.lib.php

lib_tag函数里面的

$row[‘keyword’] = $row[‘tag’];
$row[‘tag’] = dede_htmlspecialchars($row[‘tag’]);
$row[‘link’] = $cfg_cmsurl.”/tags.php?/”.urlencode($row[‘keyword’]).”/”;//这句可能有些不同,搜索前两句能正确就好

修改为

$row[‘keyword’] = $row[‘tag’];
$row[‘tag’] = dede_htmlspecialchars($row[‘tag’]);
$row[‘link’] = $cfg_cmsurl.”/tags/”.$row[‘id’].”.html”;//edit by piikee

 

tags.php

整个if else判断换成这个

if(isset($_SERVER[‘QUERY_STRING’]))
{

$tag = trim($_SERVER[‘QUERY_STRING’]);

$tags_t = explode(‘/’, $tag);
$tags=explode(‘_’,$tags_t[1]);//edit by piikee
if(isset($tags[0])) $tag = $tags[0];//edit by piikee
if(isset($tags[1])) $PageNo = intval($tags[1]);//edit by piikee
$row= $dsql->GetOne(“Select tag From `#@__tagindex` where id=”.$tag);//edit by piikee
$tag = $row[‘tag’]; //edit by piikee

}

else
{
$tag = ”;

}

 

伪静态文件.htaccess 加上如下内容:

RewriteBase /
RewriteRule ^tags/([^-]+).html$ /tags.php?/$1
RewriteRule ^tags/([^_]+)_([0-9]+).html$ /tags.php?$1/$2/ #正则解析[^_]表示一切除了_以外的字符,+表示一个或者多个。

 

修改完毕。

任何出错都是编码编码编码,注意GB2312和UTF8编码等问题,最好别直接复制本文内容,手打最好^_^。注意list_tag.htm目标链接修改一下,还有robots.txt屏蔽tags.php别让百度重复收录了。

打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注