刚刚@何日君再来 说想要这个,其实我也觉得分区页面太单调,一直在改其他东西,还没顾得上,既然有人需要,就先写出来了。
做法和之前的的带分页系列相似,只是在数据查询时改了些获取条件、表间关联条件。
先做个查询数据的php文件,暂且命名为gid.php吧,放到风格目录/forum里。代码如下:
- <?php
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- $gids = $_GET['gid'];//调用分区,get获取。
- $messagelength='500';//内容提取字节数
- $num=10;
- $begin=($_G['page']-1)*$num;
- $glist=array();
- require_once libfile('function/post');
- $rs=DB::query("
- SELECT t.*,p.message,p.pid,f.* FROM ".DB::table("forum_thread")." t LEFT JOIN ".DB::table("forum_post")." p on p.tid=t.tid LEFT JOIN ".DB::table("forum_forum")." f on f.fid=t.fid WHERE f.`fup` = '$gids' and t.displayorder>=0 and p.first=1 group by t.tid ORDER BY t.`dateline` DESC LIMIT $begin , $num");
- while ($rw=DB::fetch($rs)) {
- $rw['message']=messagecutstr($rw['message'],$messagelength,'');
- $rw['message']=dhtmlspecialchars($rw['message']);
- $glist[]=$rw;
- }
- if($gids){
- $gallnum=DB::result_first("select count(*) from ".DB::table("forum_thread")." t left join ".DB::table("forum_post")." p on p.tid=t.tid left join ".DB::table("forum_forum")." f on f.fid=t.fid where f.fup='$gid' and p.first=1");;
- $pagenav=multi($gallnum,$num,$_G['page'],"forum.php?gid=$gids");
- }
- ?>
复制代码 然后打开风格目录/forum/discuz.htm,在<!--{template common/footer}-->之前加入如下代码:
- <!--{eval require_once("template/风格目录/forum/gid.php");}-->
- <style>
- .gthread{width:1000px;background:#fff;padding:20px;margin:15px auto;}
- .gthread ul li{}
- </style>
- <!--{if $_GET['gid']}-->
- <div class="gthread">
- <ul>
- <!--{loop $glist $gv}-->
- <li><a href="forum.php?mod=viewthread&tid={$gv[tid]}"><b>{$gv[name]}</b>{$gv[subject]}</a><span class="pipe">|</span>by {$gv[author]}<span class="pipe">|</span>@{echo dgmdate({$gv[dateline]}, 'u', '9999', getglobal('setting/dateformat'))}<span class="pipe">|</span>查看:{$gv[views]}<span class="pipe">|</span>回复:{$gv[replies]}</li>
- <!--{/loop}-->
- </li>
- </div>
- <!--{/if}-->
- <!--{if $allnum>$num}-->
- <div class="nextpage">
- <a href="javasctipt:;">下一页</a>
- </div>
- <!--{/if}-->
- $pagenav
复制代码 访问分区地址不变,分页url为forum.php?gid=分区ID&page=页码。
简单补充说明:
因为discuz.htm是分区和论坛首页公用模板,所以,上面代码中的<!--{if $_GET['gid']}-->……<!--{/if}-->是让论坛首页不显示这个内容。
<!--{loop $glist $gv}-->……<!--{/loop}-->这之间的内容可以放很多的,包括,
表pre_forum_thread的所有字段,表pre_forum_post的message和pid字段,表pre_forum_forum的所有字段,此处均写为$gv[字段名]即可使用。
具体对照可查阅>> 数据字典
20170420 更正帖子数量错误:
查询数据代码中获取帖子数量及分页代码有错误,已更正。
不可全局引用,会导致个人空间主题列表页空白,可能是变量冲突,单独引用或将此查询放到模板里。
20170421 修复使用$threads导致个人空间主题列表空白的错误:
给分页统计代码外加上判断,已修复。
20180308 修复分区帖子总数错误的问题。
|