Discuz 聚合帖子
Discuz 聚合指定版块帖子或全站帖子
首先,我们的目标是,聚合某一个版块或某几个版块的下面所有帖子。
其次,如果我们没设置指定的某一个或几个版块,那么显示全站论坛版块的帖子。
一下是实现代码:
1、新建一个 php 文件 放入你的模板目录下:
如,template/default/php/base.php
内置代码如下:
- <div class="blockcode"><blockquote><?php
- if ( !defined( 'IN_DISCUZ' ) ) {
- exit( 'Access Denied' );
- }
- $forumids = array(2,36);
- $perpage = 3;
- $orderby = 'dateline desc';
- $threadlist = $post = array();
- if ( empty( $forumids ) ) {
- foreach ( C::t( 'forum_forum' )->fetch_all_forum() as $forum ) {
- $forumids[] = $forum[ 'fid' ];
- }
- }
- if ( $forumids ) {
- $filterarr = array( 'inforum' => $forumids, 'sticky' => 0, 'displayorder' => array( 0, 1, 2, 3, 4 ) );
- $count = C::t( 'forum_thread' )->count_search( $filterarr, 0 );
- $page = intval( $_G[ 'page' ] ) ? intval( $_G[ 'page' ] ) : 1;
- $start = ( $page - 1 ) * $perpage;
- if ( $start < 0 )$start = 0;
- if ( $count ) {
- require_once libfile( 'function/post' );
- foreach ( C::t( 'forum_thread' )->fetch_all_search( $filterarr, 0, $start, $perpage, $orderby, '' ) as $thread ) {
- $thread[ 'post' ] = C::t( 'forum_post' )->fetch_threadpost_by_tid_invisible( $thread[ 'tid' ] );
- $attachment = C::t( 'forum_attachment_n' )->fetch_max_image( getattachtableid( $tid ), 'pid', $thread[ 'post' ][ 'pid' ] );
- $thread[ 'aid' ] = $attachment[ 'aid' ];
- $threadlist[] = $thread;
- }
- }
-
- $NFT_Multi = multi( $count, $threads, $page, "portal.php?order=$order" );
- }
- ?>
复制代码2、假定我们要在门户首页显示这个,在 template/default/portal/index.htm 中加入
- <div class="blockcode"><blockquote><!--{eval include TPLDIR.'/include/base.php';}-->
- <!--{loop $thread_list $echo_thread}-->
- 整理可以输出 帖子的链接 标题 等等,这个就需要你自己发掘了,例如,$echo_thread[subject]
- <!--{/loop}-->
- <!--{$NFT_Multi}-->
复制代码
其中
$forumids = array(2,36); 的意思是 聚合 版块2 版块36下的帖子,也可以只写一个。
$perpage = 3; 每页显示3条,这个可以按你想要的写。