2013-06-03, 10:55 AM
(This post was last modified: 2013-06-03, 11:34 AM by zontrakulla.)
Hi everyone, I'm new to myBB. My question is, how do i get new posts number since the last login in my header?
i edited my header template and put this:
however it shows blank.
Edit:
I've added this code to global.php and now it works perfectly.
i edited my header template and put this:
New Announcements: {$lang->new_announcements}
however it shows blank.
New Announcements:
Edit:
I've added this code to global.php and now it works perfectly.
// If user is known, welcome them
if($mybb->settings['portal_showwelcome'] != 0)
{
$lang->load("portal");
if($mybb->user['uid'] != 0)
{
// Get number of new posts, threads, announcements
$query = $db->simple_select("posts", "COUNT(pid) AS newposts", "visible=1 AND dateline>'".$mybb->user['lastvisit']."' $unviewwhere");
$newposts = $db->fetch_field($query, "newposts");
if($newposts)
{
// If there aren't any new posts, there is no point in wasting two more queries
$query = $db->simple_select("threads", "COUNT(tid) AS newthreads", "visible=1 AND dateline>'".$mybb->user['lastvisit']."' $unviewwhere");
$newthreads = $db->fetch_field($query, "newthreads");
$announcementsfids = explode(',', $mybb->settings['portal_announcementsfid']);
if(is_array($announcementsfids))
{
foreach($announcementsfids as $fid)
{
$fid_array[] = intval($fid);
}
$announcementsfids = implode(',', $fid_array);
$query = $db->simple_select("threads", "COUNT(tid) AS newann", "visible=1 AND dateline>'".$mybb->user['lastvisit']."' AND fid IN (".$announcementsfids.") $unviewwhere");
$newann = $db->fetch_field($query, "newann");
}
if(!$newthreads)
{
$newthreads = 0;
}
if(!$newann)
{
$newann = 0;
}
}
else
{
$newposts = 0;
$newthreads = 0;
$newann = 0;
}
// Make the text
if($newann == 1)
{
$lang->new_announcements = $lang->new_announcement;
}
else
{
$lang->new_announcements = $lang->sprintf($lang->new_announcements, $newann);
}
if($newthreads == 1)
{
$lang->new_threads = $lang->new_thread;
}
else
{
$lang->new_threads = $lang->sprintf($lang->new_threads, $newthreads);
}
if($newposts == 1)
{
$lang->new_posts = $lang->new_post;
}
else
{
$lang->new_posts = $lang->sprintf($lang->new_posts, $newposts);
}
eval("\$welcometext = \"".$templates->get("portal_welcome_membertext")."\";");
}
else
{
$lang->guest_welcome_registration = $lang->sprintf($lang->guest_welcome_registration, $mybb->settings['bburl'] . '/member.php?action=register');
$mybb->user['username'] = $lang->guest;
eval("\$welcometext = \"".$templates->get("portal_welcome_guesttext")."\";");
}
$lang->welcome = $lang->sprintf($lang->welcome, $mybb->user['username']);
eval("\$welcome = \"".$templates->get("portal_welcome")."\";");
if($mybb->user['uid'] == 0)
{
$mybb->user['username'] = "";
}
}