欢迎来到素材无忧网,按 + 收藏我们
登录 注册 退出 找回密码

discuz 帖子列表页调用摘要代码

时间: 2019-05-24 11:57 阅读: 作者:素材无忧网

需要修改文件/source/module/forum/forum_forumdisplay.php 第812行左右找到:
$threadids[$threadindex] = $thread['tid'];
复制代码
在其下方增加
//内容摘要
         include_once libfile('function/post');
        include_once libfile('function/attachment');
        $thread['post'] = C::t('forum_post')->fetch_all_by_tid_position($thread['posttableid'],$thread['tid'],1);
        $thread['post'] = array_shift($thread['post']);
        $thread['preview'] = messagecutstr($thread['post']['message'], 200);
        $attachments = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$thread['post']['tid'], 'pid', $thread['post']['pid']);
        $attachs = $imgattachs = array();
        foreach(C::t('forum_attachment')->fetch_all_by_id('pid', $thread['post']['pid'], 'aid') as $attach) {
                $attach = array_merge($attach, $attachments[$attach['aid']]);
                $attach['filenametitle'] = $attach['filename'];
                $attach['ext'] = fileext($attach['filename']);
                getattach_row($attach, $attachs, $imgattachs);
        }
        $thread['attachments'] = $imgattachs;
        //内容摘要END


模板中调用代码:
$thread['preview']
复制代码

20161221更新
另一些直接写在模板的方法:
代码1:
<!--{eval require_once(DISCUZ_ROOT."./source/function/function_post.php");}-->
<!--{echo messagecutstr(DB::result_first('SELECT `message` FROM '.DB::table('forum_post').' WHERE `tid` ='.$thread[tid].' AND `first` =1'),300);}-->


代码2:
<!--{eval $threadlist_message = DB::result(DB::query("SELECT message FROM ".DB::table('forum_post')." WHERE `tid` = $thread[tid]  AND `first` =1"));}-->
<!--{echo cutstr($threadlist_message,300)}-->

都有效,任选其一即可。

版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!

转载请注明: discuz 帖子列表页调用摘要代码

标签:  
相关文章
模板推荐