开发者社区> 问答> 正文

【discuz伪静态】系列之二:“导读”页面优化(title/作者nofollow/rss订阅等)

此篇为系列教程,为还在为dz伪静态烦恼的站长们助力(译版:为了申请版主而做准备)!
以discuz!3.2 + nginx为例!Apache,iis请自行转换!

【重要提醒:修改前请备份源文件,如果发现修改后进入页面空白,请是否修改正确!】

由于这个是把重要的代码全部【code】化,所以看起来会比较累!
所以提供百度文库及其豆丁版(都是本人上传,版主如果觉得有广告嫌疑请删除此段)
百度文库:暂未收录
豆丁:http://www.docin.com/p-1150298948.html


1、增加伪静态规则,以Nginx为例:
rewrite ^([^\.]*)/latest-([a-z]+)-([0-9]+)\.html$ $1/forum.php?mod=guide&view=$2&page=$3 last;
注意:必须放在 rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last; 之前任一行,否则无法生效。修改后需要重载Nginx。


2、让“导读”页面上的 最新XX 、抢沙发 等(除“我的帖子”)标签的链接伪静态化。打开 forum/guide 模板文件,将
<ul id="thread_types" class="ttp bm cl">
后面的5个li行替换为:
<li $currentview['hot']><a href="latest-hot-1.html">{lang guide_hot}</a></li>
<li $currentview['digest']><a href="latest-digest-1.html">{lang guide_digest}</a></li>
<li $currentview['new']><a href="latest-new-1.html">{lang guide_new}</a></li>
<li $currentview['newthread']><a href="latest-newthread-1.html">{lang guide_newthread}</a></li>
<li $currentview['sofa']><a href="latest-sofa-1.html">{lang guide_sofa}</a></li>




{lang title}
替换为:
<div class="tf" style="padding-left:5px;">主题列表</div>


3、将底部翻页按钮前的“导读首页”改为“最新热门”,并将其链接伪静态化。打开 forum/guide 模板文件,将
<span class="pgb y"><a href="forum.php?mod=guide">{lang guide_index}</a></span>
修改为
<span class="pgb y"><a href="latest-hot-1.html">最新热门</a></span>




4、将面包屑导航条中的“导读”改为站名,并使后面的链接伪静态化。
打开 forum/guide 模板文件,将
<a href="./" class="nvhm" title="{lang homepage}">$_G[setting][bbname]</a><!--{if helper_access::check_module('guide')}--><em>»</em><a href="forum.php?


mod=guide&view=index">{lang guide}</a><!--{/if}-->

修改为
<a href="./" class="nvhm" title="{lang homepage}"></a><em>»</em><a href="./">$_G[setting][bbname]</a>


打开 source/module/forum/forum_guide 文件,将
<a href="forum.php?mod=guide&view='.$view.'">
替换为
<a href="latest-'.$view.'-1.html">




5、删除title中的“导读-”。打开 source/module/forum/forum_guide 文件,将
$navtitle = $lang['guide'].'-'.$lang['guide_'.$view];
替换为
$navtitle = $lang['guide_'.$view].$title_page;
并在前面增加一行
if($_GET['page'] > 1) { $title_page = '(第'.$_GET['page'].'页)'; }




6、让“导读”页面上的翻页按钮静态化。
打开 source/module/forum/forum_guide 文件,将
$theurl = 'forum.php?mod=guide&view='.$view;
剪切到其后
if($view == 'my') {
里面的第一行,然后在
$data[$view] = get_guide_list($view, $start, $perpage);
前增加一行
$theurl = 'latest-'.$view;
(此项操作的目的是使“我的帖子”页面的翻页功能不受影响)。


接着将
$multipage = multi
修改为
$multipage = multi_guide
(将翻页按钮由标准改为自定义)。


打开 source/function/function_core 文件,在
function simplepage($num, $perpage, $curpage, $mpurl) {
前面增加一段(定义multi_guide):
function multi_guide($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page_guide::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}



进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_guide.php 。并依次修改 helper_page_guide.php 文件中的以下部分:
将 helper_page 修改为
helper_page_guide
(共两处,其中文件头注释中的那处无关紧要);将
$pagevar = 'page=';
修改为
$pagevar = '-';



$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';
修改为
$jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\'.html


\'; doane(event);';

(此项操作使手动输入页码翻页时链接静态化);



return $mpurl.$separator.$pagevar.$page;
修改为
return substr($mpurl, 0, -1).$separator.$pagevar.$page.'.html';
(翻页页码链接静态化)


7、首页“最新回复”链接静态化。打开 forum/discuz 模板,将
forum.php?mod=guide&view=new
替换为
[code]latest-new-1.html[/code]




8、将“我的帖子”标签链接加上nofollow,并且在未登录状态下不出现下拉菜单
打开 forum/guide 模板文件,将
[code]<a id="filter_special" href="forum.php?mod=guide&view=my">[/code]
修改为
[code]{if $_G['uid']}<a id="filter_special" href="forum.php?mod=guide&view=my">{else}<a href="forum.php?mod=guide&view=my" rel="nofollow">{/if}[/code]

[code]<!--{if !IS_ROBOT}-->[/code]
修改为
[code]<!--{if $_G['uid']}-->[/code]




9、整理“导读”页面“rss订阅”的代码。打开 source/module/forum/forum_guide 文件,

[code]"    <link>{$_G[siteurl]}forum.php?mod=guide&view=$view</link>\n".[/code]
修改为
[code]"    <link>{$_G[siteurl]}latest-$view-1.html</link>\n".[/code]



[code]Copyright(C) {$_G[setting][bbname]}[/code]
替换为
[code]Copyright (C) 建站年份-当前年份 网址[/code]



[code]Discuz! Board by Comsenz Inc.[/code]
修改为
[code]{$_G[setting][bbname]}[/code]



[code]$filename = $_G['siteurl'].$_G['setting']['attachurl'].'forum/'.$attachfile;[/code]
替换为
[code]$filename = $_G['setting']['attachurl'].'forum/'.$attachfile;[/code]




10、去掉最后回复时间及其作者的链接,给主帖作者链接加上nofollow。打开 forum/guide_list_row 模板,

[code]<td class="num"><a href="forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra" class="xi2">$thread[replies]</a><em><!--{if $thread['isgroup'] != 1}-->$thread[views]


<!--{else}-->{$groupnames[$thread[tid]][views]}<!--{/if}--></em></td> 后面的 <td class="by">[/code]
段替换为:
[code]<td class="by">
<cite><!--{if $thread['lastposter']}-->$thread[lastposter]<!--{else}-->$_G[setting][anonymoustext]<!--{/if}--></cite>
<em>$thread[lastpost]</em>
</td>[/code]



[code]<a href="home.php?mod=space&uid=$thread[authorid]" c="1">[/code]
修改为
[code]<a href="home.php?mod=space&uid=$thread[authorid]" rel="nofollow" target="_blank" c="1">[/code]




11、删除标题前面图标的链接。打开 forum/guide_list_row 模板,删除
[code]<a href="forum.php?mod=viewthread&tid=$thread[icontid]&{if $_GET['archiveid']}[/code] 起至 [code]{lang target_blank}" target="_blank"> [/code]的整段代码,
同时将随后最近一个 <!--{/if}--> 后面的 </a> 删除




12、删除回复数的链接。同样是 forum/guide_list_row 模板,将
[code]<a href="forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra" class="xi2">$thread[replies]</a>[/code]
替换为
[code]$thread[replies][/code]




后面几篇明天继续


【discuz伪静态】系列之一:http://bbs.aliyun.com/read/244384.html  
【discuz伪静态】系列之二:http://bbs.aliyun.com/read/244388.html  
【discuz伪静态】系列之三: http://bbs.aliyun.com/read/244531.html
【discuz伪静态】系列之四:http://bbs.aliyun.com/read/244529.html
【discuz伪静态】系列之五(附件篇):


展开
收起
wgrid.cn 2015-05-21 23:55:42 15748 0
1 条回答
写回答
取消 提交回答
  • Re:【discuz伪静态】系列之二:“导读”页面优化(title/作者nofollow/rss订阅 ..
    支持原创教程~
    2015-05-28 14:46:17
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
QQ移送页面框架优化实践 立即下载
QQ移动页面框架优化实践 立即下载
低代码开发师(初级)实战教程 立即下载