立即注册 找回密码

QQ登录

只需一步,快速开始

查看: 31|回复: 0

[Discuz X3.2 通用教程] 修改discuz DZ X3自带首页四格代码部分解析

[复制链接]
发表于 3 小时前 | 显示全部楼层 |阅读模式
道勤网-数据www.daoqin.net

亲注册登录道勤网-可以查看更多帖子内容哦!(包涵精彩图片、文字详情等)请您及时注册登录-www.daoqin.net

您需要 登录 才可以下载或查看,没有账号?立即注册

x
discuz X3自带首页四格开启位置为:后台——论坛——首页四格。

首页四格代码展示位置:template\default\forum\discuz.htm
默认代码如下:

  1. <!--{if !empty($_G['setting']['grid']['showgrid'])}-->
  2. <!-- index four grid -->
  3. <div class="fl bm">
  4. <div class="bm bmw cl">
  5. <div id="category_grid" class="bm_c" >
  6. <table cellspacing="0" cellpadding="0"><tr>
  7. <!--{if !$_G['setting']['grid']['gridtype']}-->
  8. <td valign="top" class="category_l1">
  9. <div class="newimgbox">
  10. <h4><span class="tit_newimg"></span>{lang latest_images}</h4>
  11. <div class="module cl slidebox_grid" style="width:218px">
  12. <script type="text/javascript">
  13. var slideSpeed = 5000;
  14. var slideImgsize = [218,200];
  15. var slideBorderColor = '{$_G['style']['specialborder']}';
  16. var slideBgColor = '{$_G['style']['commonbg']}';
  17. var slideImgs = new Array();
  18. var slideImgLinks = new Array();
  19. var slideImgTexts = new Array();
  20. var slideSwitchColor = '{$_G['style']['tabletext']}';
  21. var slideSwitchbgColor = '{$_G['style']['commonbg']}';
  22. var slideSwitchHiColor = '{$_G['style']['specialborder']}';
  23. {eval $k = 1;}
  24. <!--{loop $grids['slide'] $stid $svalue}-->
  25. slideImgs[<!--{echo $k}-->] = '$svalue[image]';
  26. slideImgLinks[<!--{echo $k}-->] = '{$svalue[url]}';
  27. slideImgTexts[<!--{echo $k}-->] = '$svalue[subject]';
  28. {eval $k++;}
  29. <!--{/loop}-->
  30. </script>
  31. <script language="javascript" type="text/javascript" src="{$_G[setting][jspath]}forum_slide.js?{VERHASH}"></script>
  32. </div>
  33. </div>
  34. </td>
  35. <!--{/if}-->
  36. <td valign="top" class="category_l2">
  37. <div class="subjectbox">
  38. <h4><span class="tit_subject"></span>{lang collection_lastthread}</h4>
  39. <ul class="category_newlist">
  40. <!--{loop $grids['newthread'] $thread}-->
  41. <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  42. <!--{eval $thread[tid]=$thread[closed];}-->
  43. <!--{/if}-->
  44. <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>
  45. <!--{/loop}-->
  46. </ul>
  47. </div>
  48. </td>
  49. <td valign="top" class="category_l3">
  50. <div class="replaybox">
  51. <h4><span class="tit_replay"></span>{lang show_newthreads}</h4>
  52. <ul class="category_newlist">
  53. <!--{loop $grids['newreply'] $thread}-->
  54. <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  55. <!--{eval $thread[tid]=$thread[closed];}-->
  56. <!--{/if}-->
  57. <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>
  58. <!--{/loop}-->
  59. </ul>
  60. </div>
  61. </td>
  62. <td valign="top" class="category_l3">
  63. <div class="hottiebox">
  64. <h4><span class="tit_hottie"></span>{lang hot_thread}</h4>
  65. <ul class="category_newlist">
  66. <!--{loop $grids['hot'] $thread}-->
  67. <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  68. <!--{eval $thread[tid]=$thread[closed];}-->
  69. <!--{/if}-->
  70. <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>
  71. <!--{/loop}-->
  72. </ul>
  73. </div>
  74. </td>
  75. <!--{if $_G['setting']['grid']['gridtype']}-->
  76. <td valign="top" class="category_l4">
  77. <div class="goodtiebox">
  78. <h4><span class="tit_goodtie"></span>{lang post_digest_thread}</h4>
  79. <ul class="category_newlist">
  80. <!--{loop $grids['digest'] $thread}-->
  81. <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
  82. <!--{eval $thread[tid]=$thread[closed];}-->
  83. <!--{/if}-->
  84. <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>
  85. <!--{/loop}-->
  86. </ul>
  87. </div>
  88. </td>
  89. <!--{/if}-->
  90. </table>
  91. </div>
  92. </div>
  93. </div>
  94. <!-- index four grid end -->
  95. <!--{/if}-->
复制代码
以上个别代码说明:
  1. {eval $k = 1;}
  2. <!--{loop $grids['slide'] $stid $svalue}-->
  3. slideImgs[<!--{echo $k}-->] = '$svalue[image]';
  4. slideImgLinks[<!--{echo $k}-->] = '{$svalue[url]}';
  5. slideImgTexts[<!--{echo $k}-->] = '$svalue[subject]';
  6. {eval $k++;}
复制代码
表示图片幻灯片从1开始,有一个幻灯片就会加1,这样会一直循环下去。比如只想显示5张幻灯图片,把$k++改成$k = 5即可
  1. var slideSpeed = 5000;
  2. var slideImgsize = [218,200];
复制代码
  1. /* 论坛首页四格 by Alice */
  2. #category_grid { padding: 0; border-top:1px solid {COMMONBORDER}; }
  3. #category_grid table { width:100%;table-layout: fixed; }
  4. #category_grid td { width: 25%; }
  5. .category_l1, .category_l2, .category_l3, .category_l4 { line-height: 25px; background: #fff; overflow: hidden; }
  6. .category_l1 { line-height: normal; }
  7. .category_l1, .category_l2, .category_l3 { background: url({IMGDIR}/category_lbg.png) no-repeat right center; }
  8. .ie6 .category_l4 { margin-right: -3px; }
  9. .slidebox_grid { position: relative; margin: 10px; border: 1px #ccc solid; }
  10. #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; }
  11. .category_newlist { padding: 10px; }
  12. .category_newlist li { background:url({IMGDIR}/dot.gif) no-repeat left center;  height: 21px; line-height:21px; overflow: hidden; padding-left:10px; }
  13. #category_grid h4 span { background:#CDCDCD; width:1px; height:30px; display:inline-block; position:absolute; left:0; top:0; }
  14. #category_grid h4 span.tit_newimg { background:#FFF; }
  15. #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; }
  16. #category_grid .newimgbox:hover h4 span.tit_newimg { background-position:0 -30px; }
  17. #category_grid .subjectbox:hover h4 span.tit_subject { background-position:0 0; }
  18. #category_grid .repalybox:hover h4 span.tit_replay { background-position:0 -30px; }
  19. #category_grid .hottiebox:hover h4 span.tit_hottie { background-position:0 -60px; }
  20. #category_grid .goodtiebox:hover h4 span.tit_goodtie { background-position:0 -90px; }
复制代码
  1. $grids['slide'][$ithread['tid']] = array(
  2. 'image' => $imageurl,
  3. 'url' => 'forum.php?mod=viewthread&tid='.$ithread['tid'],
  4. 'subject' => $ithread['subject']
  5. );
复制代码
在上面代码下面增加:
  1. rsort($grids['slide']);
复制代码
即修改成如下所示代码:
  1. $grids['slide'][$ithread['tid']] = array(
  2. 'image' => $imageurl,
  3. 'url' => 'forum.php?mod=viewthread&tid='.$ithread['tid'],
  4. 'subject' => $ithread['subject']
  5. );
  6. rsort($grids['slide']);
  7. }
  8. }
  9. $grids['cachetime'] = TIMESTAMP;
复制代码
解决X3自带首页四格最新主题和最新回复一样的问题
由于source\class\table\table_forum_thread.php文件中调用新主题的参数是 newthread,第1105行
  1. if($type == 'newthread') {
复制代码
而source\module\forum\forum_index.php里却是thread,所以默认还是调用的最新回复贴子
  1. $grids['newthread'] = C::t('forum_thread')->fetch_all_for_guide('thread', 0, array(), 0, 0, 0, 10, $_G['setting']['grid']['fids']);
复制代码
修改 thread为newthread即可,如下第159行
  1. $grids['newthread'] = C::t('forum_thread')->fetch_all_for_guide('newthread', 0, array(), 0, 0, 0, 10, $_G['setting']['grid']['fids']);
复制代码
修改图片逆序的代码是这么改的:找到
  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. foreach($grids['image'] as $tmpkey => $tmpvalue){
  4. $tmpkeys[]=$tmpkey;
  5. }
  6. array_multisort($tmpkeys,SORT_DESC,$grids['image']);  //试试能不能排序
复制代码
因为php的这个array_multisort虽然会修改key的值,但是其实dz根本不用,图片显示的完全正常

道勤主机提供365天*24小时全年全天无休、实时在线、零等待的售后技术支持。竭力为您免费处理您在使用道勤主机过程中所遇到的一切问题! 如果您是道勤主机用户,那么您可以通过QQ【792472177】、售后QQ【59133755】、旺旺【诠释意念】、微信:q792472177免费电话、后台提交工单这些方式联系道勤主机客服! 如果您不是我们的客户也没问题,点击页面最右边的企业QQ在线咨询图标联系我们并购买后,我们为您免费进行无缝搬家服务,让您享受网站零访问延迟的迁移到道勤主机的服务!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

道勤网- 推荐内容!上一条 /2 下一条

!jz_fbzt! !jz_sgzt! !jz_xgzt! 快速回复 !jz_fhlb! !jz_lxwm! !jz_gfqqq!

关于我们|手机版|小黑屋|地图|【道勤网】-www.daoqin.net 软件视频自学教程|免费教程|自学电脑|3D教程|平面教程|影视动画教程|办公教程|机械设计教程|网站设计教程 ( 皖ICP备15000319号-1 )

GMT+8, 2025-1-11 23:35

Powered by DaoQin! X3.4 © 2016-2063 Dao Qin & 道勤科技

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