DedeCMS如何实现tag标签伪静态的方法

不是别人逼你去优秀,是你自己为自己而奋斗。身体是自己的,健康是自己的,难受也是自己的,所以不要想吃什么就吃什么。

目标:使DEDECMS原来的tags.php?/bnxbcom/ 变动为/tags/bnxbcom.html 这种伪静态模式

一、dede后台开启伪静态

二、修改 /include/taglib/tag.lib.php

大约87行找到

$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";

改成

$row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";

三、修改分页代码

修改分页代码。同样打开include/arc.taglist.class.php,主要是//获得上一页和下一页的链接。将//获得上一页和下一页的链接至 //获得数字链接之间的分页函数替换:

也可以直接用下面代码替换同样部分代码

(提示:网上有文章中讲的以下代码中的"pageinfo"是错误的,应该为\&;pageinfo\&;,不然会有错误提示哦!已经代码测试OK!)

/** * 获取动态的分页列表
*

* @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>rn";
$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)
{
$prepage.="<li><a rel="nofollow noopener noreferrer" href='".$purl."-$prepagenum'.html>上一页</a></li>rn";
$indexpage="<li><a rel="nofollow noopener noreferrer" href='".$purl."-1.html'>首页</a></li>rn";
}
else
{
$indexpage="<li><a>首页</a></li>rn";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<li><a rel="nofollow noopener noreferrer" href='".$purl."-$nextpagenum.html'>下一页</a></li>rn";
$endpage="<li><a rel="nofollow noopener noreferrer" href='".$purl."-$totalpage.html'>末页</a></li>rn";
}
else
{
$endpage="<li><a>末页</a></li>rn";
}
//获得数字链接
$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>rn";
}
else
{
$listdd.="<li><a rel="nofollow noopener noreferrer" href='".$purl."-$j.html'>".$j."</a></li>rn";
}
}
$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;
}

四、打开templets/default/taglist.htm

找到

<strong>当前位置:</strong>:<a rel="nofollow noopener noreferrer" href="{dede:global.cfg_cmsurl/}/">主页</a> &gt; <a rel="nofollow noopener noreferrer" href='tags.php'>TAG标签</a> &gt; {dede:field.title /}

修改为

<strong>当前位置:</strong>:<a rel="nofollow noopener noreferrer" href="{dede:global.cfg_cmsurl/}/">主页</a> &gt; <a rel="nofollow noopener noreferrer" href='/tags.html'>TAG标签</a> &gt; {dede:field.title /}

五、httpd.ini 文件里加

RewriteRule ^(.*)/tags\.html $1/tags\.php


RewriteRule ^(.*)/tags/(.*).html $1/tags\.php\?$2



如果是HTACCESS,那使用下面规则

RewriteEngine on
RewriteBase /
RewriteRule ^tags/([0-9]+)_([0-9]+).html$        tags.php?tagid=$1&PageNo=$2 [L]
RewriteRule ^tags/([0-9]+).html$                tags.php?tagid=$1 [L]

到此这篇关于DedeCMS如何实现tag标签伪静态的方法就介绍到这了。强者向人们揭示的是确认人生的价值,弱者向人们揭示的却是对人生的怀疑。更多相关DedeCMS如何实现tag标签伪静态的方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
织梦后台文档列表添加复制文档功能支持所有模型

织梦无法上传ico图标格式文件的如何解决方法

dedecms如何实现任意页面调用当前会员信息的方

织梦dede:tag调用指定多个栏目的TAG标签

织梦栏目列表按附加表自定义字段排序