help last 5 forum on homepage

849
.

how to show last 5 forum in main page plz give a code and where put a code i am using jcms5.2.1

.
Вот (+/-)
/*
-----------------------------------------------------------------
Последние темы на форуме
-----------------------------------------------------------------
*/
$set_forum = $datauser['set_forum'] ? unserialize($datauser['set_forum']) : array();
$settings = $set['lastThemes'] ? unserialize($set['lastThemes']) : array('totalThemes' => 5, 'timeCache' => 30);
if($settings['totalThemes'] > 0 && !$set_forum['viewThemes']) { $themesOut = '';
$file_cache = 'files/cache/lastThemes.dat';
echo '<div class="phdr"><b>Последние темы форума</b></div>';
$req = mysql_query("SELECT * FROM `forum` WHERE `type`='t'" . ($rights >= 7 ? '' : " AND `close`!='1'") . " ORDER BY `time` DESC LIMIT " . $settings['totalThemes']);
while (($res = mysql_fetch_assoc($req)) !== false) {
if ($res['close']) $themesOut .= '<div class="rmenu">';
else $themesOut .= $i % 2 ? '<div class="list2">' : '<div class="list1">';
$nickUser = mysql_fetch_assoc(mysql_query("SELECT `from` FROM `forum` WHERE `type` = 'm' AND `close` != '1' AND `refid` = '" . $res['id'] . "' ORDER BY `time` DESC LIMIT 1"));
$totalPosts = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `refid`='" . $res['id'] . "'" . ($rights >= 7 ? '' : " AND `close` != '1'")), 0);
$endPage = ceil($totalPosts / $kmess);
$icons = array(
(!$res['vip'] ? '<img src="../theme/' . $set_user['skin'] . '/images/op.gif" alt=""/>' : ''),
($res['vip'] ? '<img src="../theme/' . $set_user['skin'] . '/images/pt.gif" alt=""/>' : ''),
($res['realid'] ? '<img src="../theme/' . $set_user['skin'] . '/images/rate.gif" alt=""/>' : ''),
($res['edit'] ? '<img src="../theme/' . $set_user['skin'] . '/images/tz.gif" alt=""/>' : '')
);
$themesOut .= functions::display_menu($icons, '&#160;', '&#160;') .
'<a href="forum/index.php?id=' . $res['id'] . '">' . $res['text'] . '</a> [' . $totalPosts . ']';
if ($endPage > 1) $themesOut .= '<a href="forum/index.php?id=' . $res['id'] . '&page=' . $endPage . '">&#160;>></a>';
$themesOut .= '<div class="sub">' . $res['from'];
if (!empty($nickUser['from'])) $themesOut .= '&#160;/&#160;' . $nickUser['from'];
$themesOut .= ' <span class="gray">(' . functions::display_date($res['time']) . ')</span></div></div>';
++$i;
}
if ($settings['timeCache'] > 0 && time() < (filemtime($file_cache) + $settings['timeCache'])) { echo file_get_contents($file_cache);
} else { echo $themesOut;
if($settings['timeCache'] > 0)
file_put_contents($file_cache, $themesOut);
}
}

.

too long. why don't just fetch id, text, user name? that's make page fast loading

.
Nato

last 5 forum post just mysql fetch id, text, user name. if u want don't to show closed topic just add close != 1 .

/* Showing last 5 thread */
$selectdb = mysql_query("SELECT id, text, user_name FROM forum WHERE type = t AND close != 1 ORDER BY id DESC LIMIT 5");
echo '<div class="phdr">New topic</div>';
while($last5post = mysql_fetch_array($selectdb)) {
echo '<div class="list1">• <a href="/forum/index.php?id='.$last5post['id'].'">'.$last5post['text'].'</a> ('.$last5post['user_name'].')</div>'; }

That enough. if u want show last 5 thread that use just comment. changing ORDER BY id to ORDER BY time.
Всего: 4