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]" onm ouseover="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]" onm ouseover="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]" onm ouseover="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]" onm ouseover="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; }
共同探讨,比较喜欢自带的插件!
解决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;
解决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']);
楼主的代码怕是抄来的,起码X3.4根本不是这样的,修改图片逆序的代码是这么改的:找到
$grids['image'] = C::t('forum_thread')->fetch_all_by_tid($tids);
在下面加上一个多维数组排序的代码如下:
$grids['image'] = C::t('forum_thread')->fetch_all_by_tid($tids); //进行一次排序 foreach($grids['image'] as $tmpkey => $tmpvalue){ $tmpkeys[]=$tmpkey; } array_multisort($tmpkeys,SORT_DESC,$grids['image']); //试试能不能排序
因为php的这个array_multisort虽然会修改key的值,但是其实dz根本不用,图片显示的完全正常。
标签:category,lang,grids,thread,discuz,h4,四格,DZ,grid From: https://www.cnblogs.com/moyini/p/16838792.html