DEDE織夢文章和列表頁均使用拼音,使之更適合于
POST TIME:2020-10-09
一、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。
列表頁和文章頁都采用拼音的URL形式了,
不是原來的list_1.html的形式,更有利于SEO優化搜索
主要是說明這個修改和處理的位置,可以根據自己需求進一步更改完善。
有時dede后臺生成欄目列表頁太多了時,沒有生成完就退出循環,顯示一片空白了。
原因是有可能代碼執行時間不夠,也有可能會是代碼執行分配的內存不足。
修改方法是在代碼開始執行前設置執行最大時間和內存:
set_time_limit(0); //設置代碼執行最大時間為不限制
ini_set("memory_limit", 1048576000); //設置內存限制為1G
以上設置只對本次程序運行有效。