本帖最后由 envestor 于 2008-10-16 21:49 编辑
首先,要感谢这个帖子的楼主提供的信息.因为改良是基于这个帖子而来的.
改良效果可以参照这个地址: http://bbs.jmm.name/thread-7-1-1.html (见顶楼下方的随机主题榜)
这个修改的作用其实也不用多说了,一方面可以增加会员的浏览可能性,另一方面,也是最主要的,可以增加站内链接,提高搜索引擎对该站的收录.
下面就具体讲一下如何修改. 跟这个帖子的楼主所提供的一样, 修改步骤不变, 只是把一些代码进行更换. 原有修改是实现五行两列, 我的版本是两行三列.
步骤一:
打开/templates/default/viewthread.htm
如果你想把随机贴放在帖子上方,即帖子名字下方,则搜索以下代码:
<!--{if $post['subject']}-->
<h2>$post[subject]</h2>
<!--{/if}-->
如果你想把随机贴放在帖子下方,即楼主签名栏上方,则搜索以下代码:
<!--{elseif $post['attachlist']}-->
<div class="box postattachlist">
<h4>{lang attachment}</h4>
$post[attachlist]
</div>
<!--{/if}-->
在搜索到的代码后加上以下代码:
<!--{if $post['first']}-->
<!--楼主随机显示帖子开始-->
<div class="quote" align="center">
<center><h5>随机主题榜</h5></center>
<blockquote>
<table width="100%" border="0">
<tr>
<!--{loop $new_digest_threadlist $dthread}-->
<td align="left"><img src='images/default/dotB.png' style='margin-bottom:-3px;' alt='' /><a href="viewthread.php?tid=$dthread[tid]" $dthread['highlight'] title='随机主题 {LF}
所在论坛: $dthread[forumname]{LF}
主题标题: $dthread[subject]{LF}
主题作者: $dthread[author]{LF}
发表时间: $dthread[date]{LF}
浏览次数: $dthread[views] 次{LF}
回复次数: $dthread[replies] 次{LF}
最后回复: $dthread[lastreplytime]{LF}{lang lastpost}: $dthread[lastposter]'>$dthread[view_subject]</a></td>
<!--{/loop}-->
</tr>
<tr>
<!--{loop $new_reply_threadlist $rthread}-->
<td align="left"><img src='images/default/dotB.png' style='margin-bottom:-3px;' alt='' /><a href="viewthread.php?tid=$rthread[tid]" $rthread['highlight'] title='最新回复 {LF}
所在论坛: $rthread[forumname]{LF}
主题标题: $rthread[subject]{LF}
主题作者: $rthread[author]{LF}
发表时间: $rthread[date]{LF}
浏览次数: $rthread[views] 次{LF}
回复次数: $rthread[replies] 次{LF}
最后回复: $rthread[lastreplytime]{LF}{lang lastpost}: $rthread[lastposter]'>$rthread[view_subject]</a></td>
<!--{/loop}-->
</tr>
</table>
</blockquote>
</div>
<!--楼主随机显示帖子结束-->
<!--{/if}-->
步骤二:
打开根目录下的viewthread.php文件,搜索以下代码:
$thread['subjectenc'] = rawurlencode($thread['subject']);
在这段代码上方插入以下代码:
//---随机主题开始------------------------------------------
//最新回复
$hack_cut_str = 28; //标题字数,可调整
$hack_cut_strauthor = 9;
$new_reply_threadlist = array();
$rthread = array();
$query = $db->query("SELECT t.*, f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE t.fid<>'$fid' AND f.fid=t.fid AND t.closed NOT LIKE 'moved|%' AND t.replies !=0 AND f.fid not in (0) AND t.displayorder not in (-1,-2) ORDER BY t.lastpost DESC LIMIT 0, 3");
while($rthread = $db->fetch_array($query)) {
$rthread['forumname'] = ereg_replace('<[^>]*>','',$rthread['name']);
$rthread['view_subject'] = cutstr($rthread['subject'],$hack_cut_str);
$rthread['view_lastposter'] = cutstr($rthread['lastposter'],$hack_cut_strauthor);
$rthread['date']= gmdate("$dateformat $timeformat", $rthread['dateline'] + $timeoffset * 3600);
$rthread['lastreplytime']= gmdate("$dateformat $timeformat", $rthread[lastpost] + ($timeoffset * 3600));
$new_reply_threadlist[] = $rthread;
}
//随机主题
$hack_cut_str = 28; //标题字数,可调整
$hack_cut_strauthor = 9;
$new_digest_threadlist = array();
$dthread = array();
$query = $db->query("SELECT t.*, f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE t.fid<>'$fid' AND f.fid=t.fid AND t.closed NOT LIKE 'moved|%' ORDER by rand() DESC LIMIT 0, 3");
while($dthread = $db->fetch_array($query)) {
$dthread['forumname'] = ereg_replace('<[^>]*>','',$dthread['name']);
$dthread['view_subject'] = cutstr($dthread['subject'],$hack_cut_str);
$dthread['view_lastposter'] = cutstr($dthread['lastposter'],$hack_cut_strauthor);
$dthread['date']= gmdate("$dateformat $timeformat", $dthread['dateline'] + $timeoffset * 3600);
$dthread['lastreplytime']= gmdate("$dateformat $timeformat", $dthread[lastpost] + ($timeoffset * 3600));
$new_digest_threadlist[] = $dthread;
}
//---随机主题结束------------------------------------------
到这里就基本完成了。最后再把附件里面的那个小图片下载后上传到/images/dafault文件夹中,全部完成。
最后几点说明:
1、行列数是可以根据个人喜好进行调节的,但是行数和列数中必须要有一个是二。因为以上修改只根据两个函数进行判断挑选随机贴。
2、行数和列数其中必须有一个是二,这个二对应了代码中“最新主题”和“最新回复”两个大类。具体每个大类里面需要显示多少个帖子,可以在步骤二中添加的代码中修改,具体如下:
$query = $db->query("SELECT t.*, f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE t.fid<>'$fid' AND f.fid=t.fid AND t.closed NOT LIKE 'moved|%' AND t.replies !=0 AND f.fid not in (0) AND t.displayorder not in (-1,-2) ORDER BY t.lastpost DESC LIMIT 0, 3");
最后那个0,3当中的3就是具体每大类想显示的贴数了。 |