phpBB3: How to Display Number of Posts Since Last Visit?

approximately 2 minutes of reading

Members of your phpBB community may find it very useful and convenient to get number of posts since their last visit. Usually this information is rendered on top of the board template, next to default, essential header links. If for example number of posts since last visit is not greater than zero, user immediately knows that and therefore can skip any scrolling or clicking on explicit link (with new posts) to save some time.

Unfortunately this functionality is not shipped by phpBB by default and it requires a small modification of both core logic of the phpBB as well as a single change of a template used by your community.

Open includes/functions.php and try to find line:

$tz = ($user->data['user_id'] != ANONYMOUS) ? strval(doubleval($user->data['user_timezone'])) : strval(doubleval($config['board_timezone']));

After this line add:

$sql = "SELECT COUNT(post_id) as total
        FROM " . POSTS_TABLE . "
        WHERE post_time >= " . $user->data['user_lastvisit'] . "
        AND poster_id != " . $user->data['user_id'];

        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $total = $row['total'];

Note that the line you need to search for may look a little bit differently. ⚠️

In the same file search for:

'U_SEARCH_NEW' => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=newposts'),

After this line add:

'TOTAL' => $total,

Save the file and open:

styles/<template name>/template/index_body.html

Search for:

<a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a>

and replace this line with:

<a href="{U_SEARCH_NEW}">{L_SEARCH_NEW} ({TOTAL})</a>

This is it.

 


Words: 278
Published in: PHP · phpBB
Last Revision: December 15, 2022

Related Articles   📚