Not Solved [resolved] Get new post numbers in header
#1
Not Solved
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:

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'] = "";
    }
} 
Reply
#2
Not Solved
put this code in header_welcomeblock_member:
NewPosts: {$lang->new_posts}
Reply
#3
Not Solved
This user has been denied support. This user has been denied support.
I don't mean to bring an old post out of the grave, but it's a good post.

I do want to ask, should the "visible=1" in the query be "p.visible=1" to not show drafts and other hidden posts?
-Sparkks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)