首页四格最新主题排序算法,如何修改为回复时间排序 New
算法在source/module/forum/forum_index.php$grids = array();if($_G['setting']['grid']['showgrid']) { loadcache('grids'); $cachelife = $_G['setting']['grid']['cachelife'] ? $_G['setting']['grid']['cachelife'] : 600; $now = dgmdate(TIMESTAMP, lang('forum/misc', 'y_m_d')).' '.lang('forum/misc', 'week_'.dgmdate(TIMESTAMP, 'w')); if(TIMESTAMP - $_G['cache']['grids']['cachetime'] < $cachelife) { $grids = $_G['cache']['grids']; } else { $images = array(); $_G['setting']['grid']['fids'] = in_array(0, $_G['setting']['grid']['fids']) ? 0 : $_G['setting']['grid']['fids']; if($_G['setting']['grid']['gridtype']) { $grids['digest'] = C::t('forum_thread')->fetch_all_for_guide('digest', 0, array(), 3, 0, 0, 10, $_G['setting']['grid']['fids']); } else { $images = C::t('forum_threadimage')->fetch_all_order_by_tid_for_guide(10, 0, $_G['setting']['grid']['fids']); foreach($images as $key => $value) { $tids[$value['tid']] = $value['tid']; } $grids['image'] = C::t('forum_thread')->fetch_all_by_tid($tids); } $grids['newthread'] = C::t('forum_thread')->fetch_all_for_guide('newthread', 0, array(), 0, 0, 0, 10, $_G['setting']['grid']['fids']); $grids['newreply'] = C::t('forum_thread')->fetch_all_for_guide('reply', 0, array(), 0, 0, 0, 10, $_G['setting']['grid']['fids']); $grids['hot'] = C::t('forum_thread')->fetch_all_for_guide('hot', 0, array(), 3, 0, 0, 10, $_G['setting']['grid']['fids']); $_G['forum_colorarray'] = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282'); foreach($grids as $type => $gridthreads) { foreach($gridthreads as $key => $gridthread) { $gridthread['dateline'] = str_replace('"', '\'', dgmdate($gridthread['dateline'], 'u', '9999', getglobal('setting/dateformat'))); $gridthread['lastpost'] = str_replace('"', '\'', dgmdate($gridthread['lastpost'], 'u', '9999', getglobal('setting/dateformat'))); if($gridthread['highlight'] && $_G['setting']['grid']['highlight']) { $string = sprintf('%02d', $gridthread['highlight']); $stylestr = sprintf('%03b', $string); $gridthread['highlight'] = ' style="'; $gridthread['highlight'] .= $stylestr ? 'font-weight: bold;' : ''; $gridthread['highlight'] .= $stylestr ? 'font-style: italic;' : ''; $gridthread['highlight'] .= $stylestr ? 'text-decoration: underline;' : ''; $gridthread['highlight'] .= $string ? 'color: '.$_G['forum_colorarray'][$string] : ''; $gridthread['highlight'] .= '"'; } else { $gridthread['highlight'] = ''; } if($_G['setting']['grid']['textleng']) { $gridthread['oldsubject'] = dhtmlspecialchars($gridthread['subject']); $gridthread['subject'] = cutstr($gridthread['subject'], $_G['setting']['grid']['textleng']); } $grids[$type][$key] = $gridthread; } } if(!$_G['setting']['grid']['gridtype']) { $grids['slide'] = $focuspic = $focusurl = $focustext = array(); $grids['focus'] = 'config=5|0xffffff|0x0099ff|50|0xffffff|0x0099ff|0x000000'; foreach($grids['image'] as $ithread) { if($ithread['displayorder'] < 0) { continue; } if($images[$ithread['tid']]['remote']) { $imageurl = $_G['setting']['ftp']['attachurl'].'forum/'.$images[$ithread['tid']]['attachment']; } else { $imageurl = $_G['setting']['attachurl'].'forum/'.$images[$ithread['tid']]['attachment']; } $grids['slide'][$ithread['tid']] = array( 'image' => $imageurl, 'url' => 'forum.php?mod=viewthread&tid='.$ithread['tid'], 'subject' => addslashes($ithread['subject']) ); } $grids['slide'] = array_reverse($grids['slide'], true); } $grids['cachetime'] = TIMESTAMP; savecache('grids', $grids); }模板插入点
template/default/touch/forum/discuz.htm
</div> <div id="tabs-box" class="swiper-container listbox cl"> <div class="swiper-wrapper"> <div class="swiper-slide"> <ul> <!--{loop $grids['newthread'] $thread}--> <!--{if !$thread['forumstick'] && $thread['closed'] > 1 && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}--> <!--{eval $thread['tid']=$thread['closed'];}--> <!--{/if}--> <!--{eval $i++;}--> <!--{eval $typeid = $tids_typeids[$thread['tid']];}--> <li><a href="forum.php?mod=viewthread&tid=$thread['tid']"{if $thread['highlight']} $thread['highlight']{/if}><span class="mybk">[{$typeid_name[$typeid]}]</span><span class="mnum">$i</span>{$thread['oldsubject']}</a></li> <!--{/loop}--> </ul> </div>
我知道答案 回答被采纳将会获得1 贡献 已有0人回答 要修改首页四格的最新主题排序算法为按回复时间排序,你需要对 `source/module/forum/forum_index.php` 文件中的相关代码进行调整。具体来说,你需要修改 `fetch_all_for_guide` 方法的调用参数,以确保主题按回复时间排序。
以下是具体的修改步骤:
1. **找到 `fetch_all_for_guide` 方法的调用**:
在 `forum_index.php` 文件中,找到以下代码段:
$grids = C::t('forum_thread')->fetch_all_for_guide('newthread', 0, array(), 0, 0, 0, 10, $_G);
2. **修改排序参数**:
你需要将 `fetch_all_for_guide` 方法的第一个参数从 `'newthread'` 改为 `'reply'`,以便按回复时间排序。修改后的代码如下:
$grids = C::t('forum_thread')->fetch_all_for_guide('reply', 0, array(), 0, 0, 0, 10, $_G);
3. **保存并测试**:
保存文件后,刷新你的网站首页,查看四格中的主题是否已按回复时间排序。
### 详细解释:
- `fetch_all_for_guide` 方法的第一个参数是排序类型,`'newthread'` 表示按最新主题排序,而 `'reply'` 表示按最新回复排序。
- 其他参数保持不变,以确保获取的主题数量和其他条件不受影响。
### 注意事项:
- 在修改代码之前,建议备份 `forum_index.php` 文件,以防止修改错误导致网站无法正常运行。
- 如果你使用的是自定义模板,请确保模板文件 `template/default/touch/forum/discuz.htm` 中的相关代码与修改后的逻辑兼容。
通过以上步骤,你应该能够成功将首页四格的最新主题排序算法修改为按回复时间排序。如果还有其他问题,欢迎继续提问!
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。 要将首页四格的最新主题排序算法修改为按回复时间排序,你需要修改 `source/module/forum/forum_index.php` 文件中的相关代码。具体来说,你需要调整 `fetch_all_for_guide` 方法的调用参数,使其按照回复时间排序。
以下是修改步骤:
1. **找到 `fetch_all_for_guide` 方法的调用**:
在 `forum_index.php` 文件中,找到以下代码:
$grids = C::t('forum_thread')->fetch_all_for_guide('newthread', 0, array(), 0, 0, 0, 10, $_G);
2. **修改排序参数**:
将 `'newthread'` 修改为 `'reply'`,这样就会按照回复时间排序。修改后的代码如下:
$grids = C::t('forum_thread')->fetch_all_for_guide('reply', 0, array(), 0, 0, 0, 10, $_G);
3. **保存并测试**:
保存文件后,刷新首页,查看四格中的主题是否按照回复时间排序。
### 详细解释:
- `fetch_all_for_guide` 方法的第一个参数是排序方式,`'newthread'` 表示按发帖时间排序,`'reply'` 表示按最后回复时间排序。
- 其他参数保持不变,确保其他功能不受影响。
### 注意事项:
- 修改代码前,建议备份原文件,以防修改出错。
- 如果你使用的是自定义模板,确保模板文件 `template/default/touch/forum/discuz.htm` 中的相关代码也适配了新的排序方式。
### 进一步优化:
如果你希望进一步优化排序逻辑,可以在 `fetch_all_for_guide` 方法中添加自定义排序条件。例如,你可以结合 `ORDER BY` 语句来实现更复杂的排序逻辑。
$grids = C::t('forum_thread')->fetch_all_for_guide('reply', 0, array(), 0, 0, 0, 10, $_G, 'lastpost DESC');
这样,主题将按照最后回复时间降序排列。
### 总结:
通过修改 `fetch_all_for_guide` 方法的排序参数,你可以轻松实现首页四格主题按回复时间排序的需求。如果你有其他定制化需求,可以根据 Discuz! 开发手册进一步调整代码。
如果有其他问题,欢迎继续咨询!
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
页:
[1]