Discuz! 获取所有分区及板块代码的秘密
在网站开发中,灵活运用DIY和代码调用是关键。当DIY无法满足需求时,可以通过代码来获取所需内容。以下代码是从关于我们插件中提取出来的,可用于其他页面,只需确保调用时与存放的文件名统一,并注意避开与论坛首页、分区、门户文章模板变量的冲突。以下是1.php代码,将其另存为testsitemap.php并放置于网站根目录。请注意,文件名可自定义,但需在调用时保持一致。同时,记得赋予正确的文件权限以保证代码能够正常执行。
<?php
/**
*网页地图获取程序
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
require_once libfile('function/forumlist');
$newthreads = round((TIMESTAMP - $_G['member']['lastvisit'] + 600) / 1000) * 1000;
$catlist = $forumlist = $forumname = array();
$todayposts = 0;
$postdata = $_G['cache']['historyposts'] ? explode("\t", $_G['cache']['historyposts']) : array(0,0);
$postdata = intval($postdata);
$postdata = intval($postdata);
if(!defined('FORUM_INDEX_PAGE_MEMORY') || !FORUM_INDEX_PAGE_MEMORY) {
$forums = C::t('forum_forum')->fetch_all_by_status(1);
$fids = array();
foreach($forums as $forum) {
$fids[$forum['fid']] = $forum['fid'];
}
$forum_access = array();
if(!empty($_G['member']['accessmasks'])) {
$forum_access = C::t('forum_access')->fetch_all_by_fid_uid($fids, $_G['uid']);
}
$forum_fields = C::t('forum_forumfield')->fetch_all($fids);
foreach($forums as $forum) {
$forum = array_merge($forum, $forum_fields[$forum['fid']]);
if($forum_access['fid']) {
$forum = array_merge($forum, $forum_access[$forum['fid']]);
}
$forumname[$forum['fid']] = strip_tags($forum['name']);
$forum['extra'] = empty($forum['extra']) ? array() : dunserialize($forum['extra']);
if(!is_array($forum['extra'])) {
$forum['extra'] = array();
}
if($forum['type'] != 'group') {
$todayposts += $forum['todayposts'];
if($forum['type'] == 'forum' && isset($catlist[$forum['fup']])) {
if(forum($forum)) {
$catlist[$forum['fup']]['forums'][] = $forum['fid'];
$forum['orderid'] = $catlist[$forum['fup']]['forumscount']++;
$forum['subforums'] = '';
$forumlist[$forum['fid']] = $forum;
}
} elseif(isset($forumlist[$forum['fup']])) {
$forumlist[$forum['fup']]['todayposts'] += $forum['todayposts'];
if($_G['setting']['subforumsindex'] && $forumlist[$forum['fup']]['permission'] == 2 && !($forumlist[$forum['fup']]['simple'] & 16) || ($forumlist[$forum['fup']]['simple'] & 8)) {
$forumurl = !empty($forum['domain']) && !empty($_G['setting']['domain']['root']['forum']) ? 'http://'.$forum['domain'].'.'.$_G['setting']['domain']['root']['forum'] : 'forum.php?mod=forumdisplay&fid='.$forum['fid'];
$forumlist[$forum['fup']]['subforums'] .= (empty($forumlist[$forum['fup']]['subforums']) ? '' : ', ').'<a href="'.$forumurl.'" '.(!empty($forum['extra']['namecolor']) ? ' style="color: ' . $forum['extra']['namecolor'].';"' : '') . '>'.$forum['name'].'</a>';
}
}
} else {
if($forum['moderators']) {
$forum['moderators'] = moddisplay($forum['moderators'], 'flat');
}
$forum['forumscount'] = 0;
$catlist[$forum['fid']] = $forum;
}
}
unset($forum_access, $forum_fields);
} else {
require_once DISCUZ_ROOT.'./source/include/misc/misc_category.php';
}
?>定制你的网页风格:轻松调用代码,HTML样式由你做主。
<div>
<!--{eval require_once DISCUZ_ROOT.'/testsitemap.php';}-->
<!--{eval $gidiconnum = 0;}-->
<!--{loop $catlist $key $cat}-->
<!--{eval $caturl = !empty($cat['domain']) && !empty($_G['setting']['domain']['root']['forum']) ? 'http://'.$cat['domain'].'.'.$_G['setting']['domain']['root']['forum'] : '';}-->
<!--{eval $gidiconnum ++;}-->
<div class="box_5">
<!--{eval $forumsss = 0;}-->
<!--{loop $cat $forumid}-->
<!--{eval $forum=$forumlist[$forumid];}-->
<!--{eval $forumsss += $forum;}-->
<!-- 占位注释 -->
<!--{/loop}-->
<div class="fs_title">
<div class="left"><span class="map_bt"><a alt="$cat" href="{if !empty($caturl)}$caturl{else}forum.php?gid=$cat{/if}" target="_blank">$cat</a></span></div>
<div class="right"></div>
</div>
<div class="blank10"></div>
<div class="map_list">
<!--{eval $fidnum = 0;}-->
<!--{loop $cat $forumid}-->
<!--{eval $forum=$forumlist[$forumid];}-->
<!--{eval $forumurl = !empty($forum['domain']) && !empty($_G['setting']['domain']['root']['forum']) ? 'http://'.$forum['domain'].'.'.$_G['setting']['domain']['root']['forum'] : 'forum.php?mod=forumdisplay&fid='.$forum['fid'];}-->
<!--{eval $fidnum ++;}-->
<a alt="$fidnum.$forum" href="$forumurl"{if $forum} target="_blank"{/if}>$fidnum.$forum</a>
<!--{/loop}-->
</div>
</div>
<div class="blank10"></div>
<!--{/loop}-->
<div class="blank10"></div>
<div class="blank10"></div>
<div class="blank10"></div>
</div>
页:
[1]