查看 1351
回复 0
Discuz 聚合指定版块帖子或全站帖子
逆风天

16

主题

0

回帖

105

积分
发表于 2021-12-4 19:46:28
显示全部楼层 阅读模式
Discuz 聚合帖子
Discuz 聚合指定版块帖子或全站帖子
首先,我们的目标是,聚合某一个版块或某几个版块的下面所有帖子。
其次,如果我们没设置指定的某一个或几个版块,那么显示全站论坛版块的帖子。
一下是实现代码:
1、新建一个 php 文件 放入你的模板目录下:
     如,template/default/php/base.php
     内置代码如下:
  1. <div class="blockcode"><blockquote><?php
  2. if ( !defined( 'IN_DISCUZ' ) ) {
  3.     exit( 'Access Denied' );
  4. }
  5. $forumids = array(2,36);
  6. $perpage = 3;
  7. $orderby = 'dateline desc';
  8. $threadlist = $post = array();
  9. if ( empty( $forumids ) ) {
  10.     foreach ( C::t( 'forum_forum' )->fetch_all_forum() as $forum ) {
  11.     $forumids[] = $forum[ 'fid' ];
  12.     }
  13. }
  14. if ( $forumids ) {
  15.     $filterarr = array( 'inforum' => $forumids, 'sticky' => 0, 'displayorder' => array( 0, 1, 2, 3, 4 ) );
  16.     $count = C::t( 'forum_thread' )->count_search( $filterarr, 0 );
  17.     $page = intval( $_G[ 'page' ] ) ? intval( $_G[ 'page' ] ) : 1;
  18.     $start = ( $page - 1 ) * $perpage;
  19.     if ( $start < 0 )$start = 0;
  20.     if ( $count ) {
  21.         require_once libfile( 'function/post' );
  22.         foreach ( C::t( 'forum_thread' )->fetch_all_search( $filterarr, 0, $start, $perpage, $orderby, '' ) as $thread ) {
  23.             $thread[ 'post' ] = C::t( 'forum_post' )->fetch_threadpost_by_tid_invisible( $thread[ 'tid' ] );
  24.             $attachment = C::t( 'forum_attachment_n' )->fetch_max_image( getattachtableid( $tid ), 'pid', $thread[ 'post' ][ 'pid' ] );
  25.             $thread[ 'aid' ] = $attachment[ 'aid' ];
  26.             $threadlist[] = $thread;
  27.         }
  28.     }
  29.   
  30.     $NFT_Multi = multi( $count, $threads, $page, "portal.php?order=$order" );
  31. }
  32. ?>
复制代码
2、假定我们要在门户首页显示这个,在 template/default/portal/index.htm 中加入
  1. <div class="blockcode"><blockquote><!--{eval include TPLDIR.'/include/base.php';}-->
  2. <!--{loop $thread_list $echo_thread}-->
  3. 整理可以输出 帖子的链接 标题 等等,这个就需要你自己发掘了,例如,$echo_thread[subject]
  4. <!--{/loop}-->
  5. <!--{$NFT_Multi}-->
复制代码

其中
$forumids = array(2,36); 的意思是 聚合 版块2 版块36下的帖子,也可以只写一个。
$perpage = 3; 每页显示3条,这个可以按你想要的写。
您需要登录后才可以回帖 登录 立即注册
QQ 快速回复 返回列表