× Didn't find what you were looking for? Ask a question
Top Posters
Since Sunday
5
o
5
4
m
4
b
4
x
4
a
4
l
4
t
4
S
4
m
3
s
3
New Topic  
bio_man bio_man
wrote...
Administrator
Valued Member
Educator
Posts: 33224
5 years ago
This code has been designed for Biology Forums to show the most popular topics in the past day, 2 days, 3 days. You are free to use it on your forum too.

Source Code

PHP Code
function Trending($limit 15$exclude_boards null)
{
	
global 
$db_prefix$modSettings$user_info$context$scripturl$settings;
	

	
$past['time'] = !empty($_GET['past']) ? (int) mysql_real_escape_string($_GET['past']) : 0;
	

	
$context['page_title'] = 'Trending Topics - '.$context['forum_name'];

	
loadTemplate('Recent');
	
	
$context['sub_template'] = 'trending';
	
	

	
if (
$exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
	
	
$exclude_boards = array($modSettings['recycle_board']);
	
else
	
	
$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;

	
$time time();
	
	

	
if(
$past['time'] == 2)
	
{
	
	
$time2 $time - (86400*2);
	
	
$timing 48;
	
	
$context['past48'] = true;
	
}
	
elseif(
$past['time'] == 3)
	
{
	
	
$time2 $time - (86400*3);
	
	
$timing 72;
	
	
$context['past72'] = true;
	
}
	
else 
	
{
	
	
$time2 $time 86400;
	
	
$timing 24;
	
	
$context['past24'] = true;
	
}
	

	
$request db_query("
	
	
SELECT COUNT(mes.id_topic) as t, mes.id_topic, mes2.subject,
	
	
	
b.id_board, b.name
	
	
FROM 
{$db_prefix}messages AS mes
	
	
	
LEFT JOIN 
{$db_prefix}boards as b ON (mes.id_board = b.id_board)
	
	
	
LEFT JOIN 
{$db_prefix}topics as top ON (mes.id_topic = top.id_topic)
	
	
	
LEFT JOIN 
{$db_prefix}messages AS mes2 ON (mes2.id_msg = top.ID_FIRST_MSG)
	
	
WHERE mes.posterTime <= 
$time
	
	
	
AND mes.posterTime >= 
$time2. (empty($exclude_boards) ? '' "
	
	
	
AND b.ID_BOARD NOT IN (" 
implode(', '$exclude_boards) . ")") . "
	
	
	
AND 
$user_info[query_see_board]
	
	
GROUP BY id_topic
	
	
ORDER BY t DESC, id_topic DESC
	
	
LIMIT 
$limit"__FILE____LINE__);

	
$context['PopTopics'] = array();

	
while (
$row mysql_fetch_assoc($request))
	
{
	
	
$context['PopTopics'][] = array(
	
	
	
'coll' => $row['t'],
	
	
	
'id_topic' => $row['id_topic'],
	
	
	
'subject' => $row['subject'],
	
	
	
'board_id' => $row['id_board'],
	
	
	
'board_name' => $row['name'],
	
	
	
'timing' => $timing
	
	
);
	
}
	
mysql_free_result($request);
	

	
$context['linktree'][] = array(
	
	
'url' => $scripturl.'?action=trending',
	
	
'name' => 'Trending Topics',
	
);
}
function Trending($limit 15$exclude_boards null)
{
	
global 
$db_prefix$modSettings$user_info$context$scripturl$settings;
	

	
$past['time'] = !empty($_GET['past']) ? (int) mysql_real_escape_string($_GET['past']) : 0;
	

	
$context['page_title'] = 'Trending Topics - '.$context['forum_name'];

	
loadTemplate('Recent');
	
	
$context['sub_template'] = 'trending';
	
	

	
if (
$exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
	
	
$exclude_boards = array($modSettings['recycle_board']);
	
else
	
	
$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;

	
$time time();
	
	

	
if(
$past['time'] == 2)
	
{
	
	
$time2 $time - (86400*2);
	
	
$timing 48;
	
	
$context['past48'] = true;
	
}
	
elseif(
$past['time'] == 3)
	
{
	
	
$time2 $time - (86400*3);
	
	
$timing 72;
	
	
$context['past72'] = true;
	
}
	
else 
	
{
	
	
$time2 $time 86400;
	
	
$timing 24;
	
	
$context['past24'] = true;
	
}
	

	
$request db_query("
	
	
SELECT COUNT(mes.id_topic) as t, mes.id_topic, mes2.subject,
	
	
	
b.id_board, b.name
	
	
FROM 
{$db_prefix}messages AS mes
	
	
	
LEFT JOIN 
{$db_prefix}boards as b ON (mes.id_board = b.id_board)
	
	
	
LEFT JOIN 
{$db_prefix}topics as top ON (mes.id_topic = top.id_topic)
	
	
	
LEFT JOIN 
{$db_prefix}messages AS mes2 ON (mes2.id_msg = top.ID_FIRST_MSG)
	
	
WHERE mes.posterTime <= 
$time
	
	
	
AND mes.posterTime >= 
$time2. (empty($exclude_boards) ? '' "
	
	
	
AND b.ID_BOARD NOT IN (" 
implode(', '$exclude_boards) . ")") . "
	
	
	
AND 
$user_info[query_see_board]
	
	
GROUP BY id_topic
	
	
ORDER BY t DESC, id_topic DESC
	
	
LIMIT 
$limit"__FILE____LINE__);

	
$context['PopTopics'] = array();

	
while (
$row mysql_fetch_assoc($request))
	
{
	
	
$context['PopTopics'][] = array(
	
	
	
'coll' => $row['t'],
	
	
	
'id_topic' => $row['id_topic'],
	
	
	
'subject' => $row['subject'],
	
	
	
'board_id' => $row['id_board'],
	
	
	
'board_name' => $row['name'],
	
	
	
'timing' => $timing
	
	
);
	
}
	
mysql_free_result($request);
	

	
$context['linktree'][] = array(
	
	
'url' => $scripturl.'?action=trending',
	
	
'name' => 'Trending Topics',
	
);
}

Template

PHP Code
function template_trending()
{
	

	
global 
$context$scripturl;
	

	
theme_linktree();
	

echo
'
	
<div class="messagefilter">
	
	
<ul>
	
	
	
<li><i class="fa fa-clock-o" aria-hidden="true"></i>&nbsp;&nbsp;Trending in the past:</li>
	
	
	
<li><a href="'
,$scripturl,'?action=trending"',isset($context['past24'])?' class="selected"':'','>24 Hours</a></li>
	
	
	
<li><a href="'
,$scripturl,'?action=trending;past=2"',isset($context['past48'])?' class="selected"':'',' rel="nofollow">48 Hours</a></li>
	
	
	
<li><a href="'
,$scripturl,'?action=trending;past=3"',isset($context['past72'])?' class="selected"':'',' rel="nofollow">72 Hours</a></li>
	
	
</ul>
	
</div>
	

	
<div style="width: 90%; margin: 1em auto 0 auto;" id="trendbox">'
;
	

	
foreach (
$context['PopTopics'] as $what
	
{
	
	
echo
'
	
	
<div class="message notify information">
	
	
	
<div class="trend_div_1">
	
	
	
	
<a href="'
,$scripturl,'?topic=',$what['id_topic'], '.0">'$what['subject'], ' <span class="normaltext"><i class="fa fa-sign-out fa-fw" aria-hidden="true"></i></span></a>
	
	
	
</div>
	
	
	
<div class="trend_div_2 extra_info">
	
	
	
	
<i class="fa fa fa-sitemap fa-fw" aria-hidden="true"></i> <a href="'
,$scripturl,'?board='$what['board_id'], '">'$what['board_name'], '</a>&nbsp;&nbsp;<i class="fa  fa-reply fa-fw" aria-hidden="true"></i> <b>'$what['coll'], '</b> ',$what['coll'] != 'posts' 'post',' made in the past ',$what['timing'],' hours
	
	
	
</div>
	
	
</div>'
;
	
}
	
	

	
echo
'
	
</div>'
;
}
function template_trending()
{
	

	
global 
$context$scripturl;
	

	
theme_linktree();
	

echo
'
	
<div class="messagefilter">
	
	
<ul>
	
	
	
<li><i class="fa fa-clock-o" aria-hidden="true"></i>&nbsp;&nbsp;Trending in the past:</li>
	
	
	
<li><a href="'
,$scripturl,'?action=trending"',isset($context['past24'])?' class="selected"':'','>24 Hours</a></li>
	
	
	
<li><a href="'
,$scripturl,'?action=trending;past=2"',isset($context['past48'])?' class="selected"':'',' rel="nofollow">48 Hours</a></li>
	
	
	
<li><a href="'
,$scripturl,'?action=trending;past=3"',isset($context['past72'])?' class="selected"':'',' rel="nofollow">72 Hours</a></li>
	
	
</ul>
	
</div>
	

	
<div style="width: 90%; margin: 1em auto 0 auto;" id="trendbox">'
;
	

	
foreach (
$context['PopTopics'] as $what
	
{
	
	
echo
'
	
	
<div class="message notify information">
	
	
	
<div class="trend_div_1">
	
	
	
	
<a href="'
,$scripturl,'?topic=',$what['id_topic'], '.0">'$what['subject'], ' <span class="normaltext"><i class="fa fa-sign-out fa-fw" aria-hidden="true"></i></span></a>
	
	
	
</div>
	
	
	
<div class="trend_div_2 extra_info">
	
	
	
	
<i class="fa fa fa-sitemap fa-fw" aria-hidden="true"></i> <a href="'
,$scripturl,'?board='$what['board_id'], '">'$what['board_name'], '</a>&nbsp;&nbsp;<i class="fa  fa-reply fa-fw" aria-hidden="true"></i> <b>'$what['coll'], '</b> ',$what['coll'] != 'posts' 'post',' made in the past ',$what['timing'],' hours
	
	
	
</div>
	
	
</div>'
;
	
}
	
	

	
echo
'
	
</div>'
;
}
Read 1370 times

Related Topics

New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1101 People Browsing
Related Images
  
 26
  
 202
  
 1140
Your Opinion
Do you believe in global warming?
Votes: 370

Previous poll results: How often do you eat-out per week?