Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[已解决] DZ X3自带首页四格代码部分解析

[复制链接]
lishiminv 发表于 2013-8-12 20:14:06 | 显示全部楼层 |阅读模式
Discuz X3自带首页四格开启位置为:后台——论坛——首页四格。

首页四格代码展示位置:template\default\forum\discuz.htm
默认代码如下:
  • <!--{if !empty($_G['setting']['grid']['showgrid'])}-->
  • <!-- index four grid -->
  • <div class="fl bm">
  • <div class="bm bmw cl">
  • <div id="category_grid" class="bm_c" >
  • <table cellspacing="0" cellpadding="0"><tr>
  • <!--{if !$_G['setting']['grid']['gridtype']}-->
  • <td valign="top" class="category_l1">
  • <div class="newimgbox">
  • <h4><span class="tit_newimg"></span>{lang latest_images}</h4>
  • <div class="module cl slidebox_grid" style="width:218px">
  • <script type="text/javascript">
  • var slideSpeed = 5000;
  • var slideImgsize = [218,200];
  • var slideBorderColor = '{$_G['style']['specialborder']}';
  • var slideBgColor = '{$_G['style']['commonbg']}';
  • var slideImgs = new Array();
  • var slideImgLinks = new Array();
  • var slideImgTexts = new Array();
  • var slideSwitchColor = '{$_G['style']['tabletext']}';
  • var slideSwitchbgColor = '{$_G['style']['commonbg']}';
  • var slideSwitchHiColor = '{$_G['style']['specialborder']}';
  • {eval $k = 1;}
  • <!--{loop $grids['slide'] $stid $svalue}-->
  • slideImgs[<!--{echo $k}-->] = '$svalue[image]';
  • slideImgLinks[<!--{echo $k}-->] = '{$svalue[url]}';
  • slideImgTexts[<!--{echo $k}-->] = '$svalue[subject]';
  • {eval $k++;}
  • <!--{/loop}-->
  • </script>
  • <script language="javascript" type="text/javascript" src="{$_G[setting][jspath]}forum_slide.js?{VERHASH}"></script>
  • </div>
  • </div>
  • </td>
  • <!--{/if}-->
  • <td valign="top" class="category_l2">
  • <div class="subjectbox">
  • <h4><span class="tit_subject"></span>{lang collection_lastthread}</h4>
  • <ul class="category_newlist">
  • <!--{loop $grids['newthread'] $thread}-->
  • <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  • <!--{eval $thread[tid]=$thread[closed];}-->
  • <!--{/if}-->
  • <li><a href="forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra"{if $thread['highlight']} $thread['highlight']{/if}{if $_G['setting']['grid']['showtips']} tip="{lang title}: <strong>$thread[oldsubject]</strong><br/>{lang author}: $thread[author] ($thread[dateline])<br/>{lang show}/{lang reply}: $thread[views]/$thread[replies]" onmouseover="showTip(this)"{else} title="$thread[oldsubject]"{/if}{if $_G['setting']['grid']['targetblank']} target="_blank"{/if}>$thread[subject]</a></li>
  • <!--{/loop}-->
  • </ul>
  • </div>
  • </td>
  • <td valign="top" class="category_l3">
  • <div class="replaybox">
  • <h4><span class="tit_replay"></span>{lang show_newthreads}</h4>
  • <ul class="category_newlist">
  • <!--{loop $grids['newreply'] $thread}-->
  • <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  • <!--{eval $thread[tid]=$thread[closed];}-->
  • <!--{/if}-->
  • <li><a href="forum.php?mod=redirect&tid=$thread[tid]&goto=lastpost#lastpost"{if $thread['highlight']} $thread['highlight']{/if}{if $_G['setting']['grid']['showtips']}tip="{lang title}: <strong>$thread[oldsubject]</strong><br/>{lang author}: $thread[author] ($thread[dateline])<br/>{lang show}/{lang reply}: $thread[views]/$thread[replies]" onmouseover="showTip(this)"{else} title="$thread[oldsubject]"{/if}{if $_G['setting']['grid']['targetblank']} target="_blank"{/if}>$thread[subject]</a></li>
  • <!--{/loop}-->
  • </ul>
  • </div>
  • </td>
  • <td valign="top" class="category_l3">
  • <div class="hottiebox">
  • <h4><span class="tit_hottie"></span>{lang hot_thread}</h4>
  • <ul class="category_newlist">
  • <!--{loop $grids['hot'] $thread}-->
  • <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  • <!--{eval $thread[tid]=$thread[closed];}-->
  • <!--{/if}-->
  • <li><a href="forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra"{if $thread['highlight']} $thread['highlight']{/if}{if $_G['setting']['grid']['showtips']} tip="{lang title}: <strong>$thread[oldsubject]</strong><br/>{lang author}: $thread[author] ($thread[dateline])<br/>{lang show}/{lang reply}: $thread[views]/$thread[replies]" onmouseover="showTip(this)"{else} title="$thread[oldsubject]"{/if}{if $_G['setting']['grid']['targetblank']} target="_blank"{/if}>$thread[subject]</a></li>
  • <!--{/loop}-->
  • </ul>
  • </div>
  • </td>
  • <!--{if $_G['setting']['grid']['gridtype']}-->
  • <td valign="top" class="category_l4">
  • <div class="goodtiebox">
  • <h4><span class="tit_goodtie"></span>{lang post_digest_thread}</h4>
  • <ul class="category_newlist">
  • <!--{loop $grids['digest'] $thread}-->
  • <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  • <!--{eval $thread[tid]=$thread[closed];}-->
  • <!--{/if}-->
  • <li><a href="forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra"{if $thread['highlight']} $thread['highlight']{/if}{if $_G['setting']['grid']['showtips']} tip="{lang title}: <strong>$thread[oldsubject]</strong><br/>{lang author}: $thread[author] ($thread[dateline])<br/>{lang show}/{lang reply}: $thread[views]/$thread[replies]" onmouseover="showTip(this)"{else} title="$thread[oldsubject]"{/if}{if $_G['setting']['grid']['targetblank']} target="_blank"{/if}>$thread[subject]</a></li>
  • <!--{/loop}-->
  • </ul>
  • </div>
  • </td>
  • <!--{/if}-->
  • </table>
  • </div>
  • </div>
  • </div>
  • <!-- index four grid end -->
  • <!--{/if}-->


以上个别代码说明:
  • {eval $k = 1;}
  • <!--{loop $grids['slide'] $stid $svalue}-->
  • slideImgs[<!--{echo $k}-->] = '$svalue[image]';
  • slideImgLinks[<!--{echo $k}-->] = '{$svalue[url]}';
  • slideImgTexts[<!--{echo $k}-->] = '$svalue[subject]';
  • {eval $k++;}


表示图片幻灯片从1开始,有一个幻灯片就会加1,这样会一直循环下去。比如只想显示5张幻灯图片,把$k++改成$k = 5即可。
  • var slideSpeed = 5000;
  • var slideImgsize = [218,200];


slideSpeed表示播放速度,slideImgsize表示播放窗口大小。
category_l1是幻灯图片代码区{lang latest_images},category_l2是最后回复{lang collection_lastthread},category_l3是最新帖子{lang show_newthreads}和热门{lang hot_thread},category_l4是精华帖子{lang post_digest_thread},对照代码看,再自己编辑吧


首页四格代码CSS位置:template\default\common\module.css
默认代码如下:
  • /* 论坛首页四格 by Alice */
  • #category_grid { padding: 0; border-top:1px solid {COMMONBORDER}; }
  • #category_grid table { width:100%;table-layout: fixed; }
  • #category_grid td { width: 25%; }
  • .category_l1, .category_l2, .category_l3, .category_l4 { line-height: 25px; background: #fff; overflow: hidden; }
  • .category_l1 { line-height: normal; }
  • .category_l1, .category_l2, .category_l3 { background: url({IMGDIR}/category_lbg.png) no-repeat right center; }
  • .ie6 .category_l4 { margin-right: -3px; }
  • .slidebox_grid { position: relative; margin: 10px; border: 1px #ccc solid; }
  • #category_grid h4 { width:100%; height: 30px; line-height: 30px; text-indent:10px; font-size: 12px; cursor: pointer; background: url({IMGDIR}/tb.png) repeat-x; position:relative; }
  • .category_newlist { padding: 10px; }
  • .category_newlist li { background:url({IMGDIR}/dot.gif) no-repeat left center;  height: 21px; line-height:21px; overflow: hidden; padding-left:10px; }
  • #category_grid h4 span { background:#CDCDCD; width:1px; height:30px; display:inline-block; position:absolute; left:0; top:0; }
  • #category_grid h4 span.tit_newimg { background:#FFF; }
  • #category_grid .newimgbox:hover h4 span, #category_grid .subjectbox:hover h4 span, #category_grid .replaybox:hover h4 span, #category_grid .hottiebox:hover h4 span, #category_grid .goodtiebox:hover h4 span { width:6px; background:url({IMGDIR}/grid.png) no-repeat 0 0;transition:width 0.2s ease 0s; overflow:hidden; }
  • #category_grid .newimgbox:hover h4 span.tit_newimg { background-position:0 -30px; }
  • #category_grid .subjectbox:hover h4 span.tit_subject { background-position:0 0; }
  • #category_grid .repalybox:hover h4 span.tit_replay { background-position:0 -30px; }
  • #category_grid .hottiebox:hover h4 span.tit_hottie { background-position:0 -60px; }
  • #category_grid .goodtiebox:hover h4 span.tit_goodtie { background-position:0 -90px; }


共同探讨,比较喜欢自带的插件!

 楼主| lishiminv 发表于 2013-8-12 21:54:56 | 显示全部楼层

解决X3自带首页四格幻灯图片最新的图片不在第一显示的问题

X3自带的首页四格幻灯图片的 图片路径、名称==都存放在$grids['slide']数组中
增加一行,对$grids['slide']数组进行一下排序就能让最新的图片显示在第1的位置。
找到source\module\forum\forum_index.php
  • $grids['slide'][$ithread['tid']] = array(
  • 'image' => $imageurl,
  • 'url' => 'forum.php?mod=viewthread&tid='.$ithread['tid'],
  • 'subject' => $ithread['subject']
  • );


在上面代码下面增加:
  • rsort($grids['slide']);


即修改成如下所示代码:
  • $grids['slide'][$ithread['tid']] = array(
  • 'image' => $imageurl,
  • 'url' => 'forum.php?mod=viewthread&tid='.$ithread['tid'],
  • 'subject' => $ithread['subject']
  • );
  • rsort($grids['slide']);
  • }
  • }
  • $grids['cachetime'] = TIMESTAMP;



回复

使用道具 举报

 楼主| lishiminv 发表于 2013-8-12 21:59:16 | 显示全部楼层

解决X3自带首页四格最新主题和最新回复一样的问题

由于source\class\table\table_forum_thread.php文件中调用新主题的参数是 newthread,第1105行
  • if($type == 'newthread') {


而source\module\forum\forum_index.php里却是thread,所以默认还是调用的最新回复贴子
  • $grids['newthread'] = C::t('forum_thread')->fetch_all_for_guide('thread', 0, array(), 0, 0, 0, 10, $_G['setting']['grid']['fids']);


修改 thread为newthread即可,如下第159行
  • $grids['newthread'] = C::t('forum_thread')->fetch_all_for_guide('newthread', 0, array(), 0, 0, 0, 10, $_G['setting']['grid']['fids']);



回复

使用道具 举报

柳拂之 发表于 2013-8-13 07:34:55 | 显示全部楼层
一看就是复制党
回复

使用道具 举报

 楼主| lishiminv 发表于 2013-8-14 22:43:13 | 显示全部楼层

对啊,从我自己网站复制过来的,没错。
回复

使用道具 举报

唐寅伯虎 发表于 2013-8-23 04:12:02 | 显示全部楼层
偶用fontpage98编辑,好像不行,楼主老兄用什么编辑器?
回复

使用道具 举报

ywmprogrammer 发表于 2013-9-26 09:51:50 | 显示全部楼层
谢谢仁兄了
回复

使用道具 举报

happy7899 发表于 2013-10-3 19:59:51 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

snnx 发表于 2013-10-27 16:52:15 | 显示全部楼层
主题显示的条数改哪个呢?
回复

使用道具 举报

drpython 发表于 2020-11-25 11:07:48 | 显示全部楼层
本帖最后由 drpython 于 2020-11-26 16:18 编辑

楼主的代码怕是抄来的,起码X3.4根本不是这样的,修改图片逆序的代码是这么改的:

找到
  1. $grids['image'] = C::t('forum_thread')->fetch_all_by_tid($tids);
复制代码



在下面加上一个多维数组排序的代码如下:


  1.                         $grids['image'] = C::t('forum_thread')->fetch_all_by_tid($tids);
  2.                        
  3.                        
  4.                         //进行一次排序
  5.                         foreach($grids['image'] as $tmpkey => $tmpvalue){
  6.                                 $tmpkeys[]=$tmpkey;
  7.                         }
  8.                         array_multisort($tmpkeys,SORT_DESC,$grids['image']);  //试试能不能排序
复制代码

因为php的这个array_multisort虽然会修改key的值,但是其实dz根本不用,图片显示的完全正常。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-5 12:36 , Processed in 0.106914 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表