discuz教程相关帖子推荐
为提高访客体验,在相关帖子下方帖子左侧增加主题封面显示。
步骤一:打开source/module/forum/forum_viewthread.php文件
搜索$post['tags'],修改为如下内容
- if($post['tags']) {
- $post['relateitem'] = getrelateitem($post['tags'], $post['tid'], $_G['setting']['relatenum'], $_G['setting']['relatetime']);
- foreach($post['relateitem'] as $k=>$img)
- {
- $threada= C::t('forum_attachment')->fetch_all_by_id('tid', $img['tid'], 'aid');
- $threadaid = reset($threada);
- $threadpic = C::t('forum_attachment_n')->fetch_by_aid_uid($threadaid['tableid'], $threadaid['aid'], $thread['authorid']);
- $thread['pic'] = $threadpic['attachment'];
- $post['relateitem'][$k]['img'] = 'data/attachment/forum/'.$thread['pic'];
- }
- }
参考上方代码后,相关帖子有封面输出了,但是部分没有封面的的主题,加载失败显示“点击重新加载”。如何处理参考下方内容:
游客,如果您要查看本帖隐藏内容请回复
步骤二:
在帖子模板中,添加如下内容:
- <div class="m_relation">
- <h3>{lang related_thread}</h3>
- <ul>
- <!--{loop $post['relateitem'] $var}-->
- <li>
- <a href="forum.php?mod=viewthread&tid=$var[tid]" title="$var[subject]" class="topic_img"><img src="$var[img]" width="100px" height="60px"></a>
- <span class="related_des">
- <div class="related_title"><a href="">$var[subject]</a></div>
- <span class="related_views"><i class="icon-eye1"></i></span>
- </span>
- </li>
- <!--{/loop}-->
- </ul>
- </div>
优化后的显示效果如下图:
获取相关帖子主题封面
以上,就是Discuz相关帖子主题封面获取的方法