Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[展示] 内容页内显示随机帖子的改良, 有助于增加收录, 附必要的设置教程

[复制链接]
envestor 发表于 2008-10-16 21:46:29 | 显示全部楼层 |阅读模式
本帖最后由 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就是具体每大类想显示的贴数了。
飘香公主 发表于 2008-10-16 22:00:07 | 显示全部楼层
不錯!支持一下!
回复

使用道具 举报

vxdll 发表于 2008-10-16 22:28:13 | 显示全部楼层
好东西啊,支持一下 明天修改!
回复

使用道具 举报

 楼主| envestor 发表于 2008-10-17 02:06:13 | 显示全部楼层
忘记说了,这个在6.1和6.0上都适用的.
回复

使用道具 举报

pp-family.net 发表于 2008-10-17 02:14:34 | 显示全部楼层
这个要啊!
回复

使用道具 举报

dailuming 发表于 2008-10-17 02:23:59 | 显示全部楼层
支持下啊 www.3633game.com
回复

使用道具 举报

迷失疯子 发表于 2008-10-17 02:25:25 | 显示全部楼层
好东西~ 收藏先!
回复

使用道具 举报

星空曙光 发表于 2008-10-17 02:44:56 | 显示全部楼层
好像不错。。记号。
回复

使用道具 举报

 楼主| envestor 发表于 2008-10-17 07:59:23 | 显示全部楼层
至少我觉得这个比根据tag来调整的楼主相关发帖要有意义些,会员能发现自己感兴趣的贴的可能性也加大了.
回复

使用道具 举报

macrossz 发表于 2008-10-17 08:42:44 | 显示全部楼层
好东西,支持
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-4-19 19:33 , Processed in 0.130483 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表