Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 2255

[3.3.x] Support Forum • Re: Need a variable to see if there are unread messages

$
0
0
Do you mean unread posts?
I use this below:

function:

Code:

public function count_unread_posts(): self|false{if ($this->user->data['is_bot'] or $this->user->data['user_id'] == ANONYMOUS or !$this->auth->acl_get('u_search') or empty($this->config['load_search'])){return false;}$count = (int) 0;$sql = 'SELECT forum_idFROM ' . FORUMS_TABLE . ' WHERE ' . $this->db->sql_in_set('forum_id', array_keys($this->auth->acl_getf('f_read', true)), false);$result = $this->db->sql_query($sql);$forum_ids = [];while ($row = $this->db->sql_fetchrow($result)){if (!$this->auth->acl_getf('f_read', $row['forum_id'])){continue;}$forum_ids[] = (int) $row['forum_id'];}$this->db->sql_freeresult($result);if (!empty($forum_ids)){$sql_where = 'AND ' . $this->db->sql_in_set('t.forum_id', $forum_ids, false);$id_ary = get_unread_topics($this->user->data['user_id'], $sql_where, '', 99999);$count = count($id_ary);}$this->template->assign_vars(['SHOW_COUNT_SEARCH_UNREAD' => $this->language->lang('SEARCH_UNREAD') . ' ' . $count,]);return $this;}
call it:

Code:

$this->count_unread_posts();
html it:

Code:

{% if SHOW_COUNT_SEARCH_UNREAD %}{# or my message to be show #}<a href="{U_SEARCH_UNREAD}">{{ SHOW_COUNT_SEARCH_UNREAD  }}</a>{% endif %}
If not, phpBB has predefined template vars for PMs and notifications/ counts these may contain "messages"

Code:

{{ NOTIFICATIONS_COUNT }}{{ UNREAD_NOTIFICATIONS_COUNT }}{{ PRIVATE_MESSAGE_COUNT }}
//edit-- fixed permissions when not in custom search page
Hope this helps ;)

Statistics: Posted by Steve — Sun Jun 22, 2025 7:22 am



Viewing all articles
Browse latest Browse all 2255

Trending Articles