DEDE织梦文章和列表页均使用拼音,使之更适合于SEO的解决方案

一、DEDE  修改默认文章命名规则
1、单独添加分类默认修改,修改文件:include/common.inc.php。
查找代码: 
//文档的默认命名规则
$art_shortname = $cfg_df_ext = '.html';
$cfg_df_namerule = '{typedir}/{Y}/{M}{D}/{aid}'.$cfg_df_ext;
更改为:
$art_shortname = $cfg_df_ext = '.html';
$cfg_df_namerule = '{typedir}/{pinyin}'.$cfg_df_ext;


2、批量添加分类默认修改,修改文件:dede/templets/catalog_add_quick.htm
查找代码:
<tr>
<td height="26" class='bline'>文章命名规则:</td>
<td class='bline'><input name="namerule" type="text" id="namerule" value="{typedir}/{Y}{M}{D}/{aid}.html" size="40" class="pubinputs" />
<img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar2')" /> </td> </tr>
更改为:
<tr>
<td height="26" class='bline'>文章命名规则:</td>
<td class='bline'><input name="namerule" type="text" id="namerule" value="{typedir}/{pinyin}.html" size="40" class="pubinputs" />
<img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar2')" /> </td> </tr>


二、DEDE  修改默认列表命名规则
1、单独添加分类默认修改,修改文件:dede/templets/catalog_add.htm
查找代码:
<tr>
<td height="26">列表命名规则:</td>
<td>
<input name="namerule2" type="text" id="namerule2" value="{typedir}/list_{tid}_{page}.html"  class="pubinputs"  style="width:250px" /> <img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/>
</td> 
</tr>
更改为:
<tr>
<td height="26">列表命名规则:</td>
<td>
<input name="namerule2" type="text" id="namerule2" value="{typedir}/{typedir}-{page}.html"  class="pubinputs"  style="width:250px" /> <img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/>
</td> 
</tr>


去除后面的文章ID
修改include/helpers/channelunit.helper.php中的:
$articleRule = str_replace('{pinyin}',GetPinyin($title).'_'.$aid,$articleRule);
$articleRule = str_replace('{py}',GetPinyin($title,1).'_'.$aid,$articleRule);
两行为:
$articleRule = str_replace('{pinyin}',GetPinyin($title),$articleRule);
$articleRule = str_replace('{py}',GetPinyin($title,1),$articleRule);
保存OK




2、批量添加分类默认修改,修改文件:dede/templets/catalog_add_quick.htm
查找代码: 
<tr>
<td height="26">列表命名规则:</td>
<td><input name="namerule2" type="text" id="namerule2" value="{typedir}/list_{tid}_{page}.html" size="40" class="pubinputs" />
 <img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')" />
</td>
</tr>
更改为:
<tr>
<td height="26">列表命名规则:</td>
<td><input name="namerule2" type="text" id="namerule2" value="{typedir}/{typedir}-{page}.html" size="40" class="pubinputs" />
 <img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')" />
</td>
</tr>


3、对于列表命名规则更改之后,子级栏目生成列表文件的时候会出错,不能创建文件,原因是{typedir}-{page}.html文件名里面重复了{typedir}的父目录
生成文件的路径就像 /parent/parent/sub-1.html,名字里面包含了一个“/”所以会出错,解决办法是:


打开include/arc.listview.class.php,找到323行代码:
$makeFile = str_replace("{page}", $this->PageNo, $makeFile);这里的$makeFile就是要生成的文件路径,处理一下就可以了。
在此行代码下面添加以下代码:
/*****自己添加的处理以{typedir}为列表命名规则时,去除生成列表文件名中重复了父目录的程序****/
if(strpos($makeFile,"//")>0){
 $tmpArr = explode("//",$makeFile);
 $makeFile = $tmpArr[0];
 if(strpos($tmpArr[1],"/")>0){
   $tmpArr1 = explode("/",$tmpArr[1]);
   $makeFile .= "/".$tmpArr1[1];
 }else{
   $makeFile .= "/".$tmpArr[1];
 }
}
/*****处理程序结束*****/


然后找到下面的:$list_1 = $this->GetTruePath().$onlyrule;代码,这个是要复制第一个列表文件为index的路径
同样在下面添加代码:
/*****自己添加的处理以{typedir}为列表命名规则时,去除生成列表文件名中重复了父目录的程序****/
if(strpos($list_1,"//")>0){
 $tmpArr = explode("//",$list_1);
 $list_1 = $tmpArr[0];
 if(strpos($tmpArr[1],"/")>0){
   $tmpArr1 = explode("/",$tmpArr[1]);
   $list_1 .= "/".$tmpArr1[1];
 }else{
   $list_1 .= "/".$tmpArr[1];
 }
}
/*****处理程序结束*****/


保存就OK。

完成后的效果可以看看http://www.zgfangyan.com/sichuanfangyan/fangyanwenzi/fangyanwenzi-2.html这个,列表页和文章页都采用拼音的URL形式了,

不是原来的list_1.html的形式,更有利于SEO优化搜索

主要是说明这个修改和处理的位置,可以根据自己需求进一步更改完善。


2014-3-5修改BY:米易工作室www.miyinet.tk QQ:86485405 工作室原创,转载请保留版权信息。
米易工作室提供高级定制企业网站,网站SEO优化,仿站,织梦模板开发,织梦二次开发;
JOOMLA,WORDPRESS等PHP,ASP系统模板、二次开发,企业多平台移动网站解决方案。


有时dede后台生成栏目列表页太多了时,没有生成完就退出循环,显示一片空白了。
原因是有可能代码执行时间不够,也有可能会是代码执行分配的内存不足。
修改方法是在代码开始执行前设置执行最大时间和内存:
set_time_limit(0); //设置代码执行最大时间为不限制
ini_set("memory_limit", 1048576000);  //设置内存限制为1G
以上设置只对本次程序运行有效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值