An easy way to show number of messages on "Messages" menu icon

You may simply display the number of messages on Messages icon without reinventing the wheel. Here is how to for UNA 9.0.0 Lucid & Protean templates. With the same logic you may do a lot of customization. These will be processed in a fraction of a second.

Make a backup  of original page.php first.
At the end of the page.php code change these lines:
------------------------------------------------------------------
if ($oPage) {

$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());
$oTemplate->getPageCode();

} else {

    $oTemplate->displayPageNotFound();
-------------------------------------------------------------------
to:
if ($oPage) {
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());}
else {
$oTemplate->displayPageNotFound();}
ob_start();
$oTemplate->getPageCode();
$currentpage = ob_get_clean();
preg_match('/bg-col-red2">([0-9]+)<\/span>\s+<\/li><li/', $currentpage,$nummessages);
if($nummessages[1]>0) {
$currentpage=str_replace('<i class="sys-icon far comments col-green1"></i>','<i class="sys-icon far comments col-green1">'.'<span style="font-size:50%;color:red;">'.$nummessages[1].'</span></i>',$currentpage);
}
echo $currentpage;
------------------------------------------------------------------------
with explanations:

if ($oPage) {
$oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
$oTemplate->setPageType ($oPage->getType());
$oTemplate->setPageContent ('page_main_code', $oPage->getCode());}
else {
$oTemplate->displayPageNotFound();}
// here we are starting the output buffer
ob_start();
$oTemplate->getPageCode();
// assigning the buffer to a string
$currentpage = ob_get_clean();
//checking how many messages are notified at UNA profile menu
preg_match('/bg-col-red2">([0-9]+)<\/span>\s+<\/li><li/', $currentpage,$nummessages);
//if there are any new message notifications then proceed
if($nummessages[1]>0) {
//put the message notification number near the messages icon
$currentpage=str_replace('<i class="sys-icon far comments col-green1"></i>','<i class="sys-icon far comments col-green1">'.'<span style="font-size:50%;color:red;">'.$nummessages[1].'</span></i>',$currentpage);
}
//sent to browser
echo $currentpage;



  • As this method reads from the actual number superficially from UNA profile menu it is needed to refresh the page to be correct.
    You may design the style of the number as you wish, different color, circled etc.
    I am not a professional, just thought this may help others.


  • 228
  • More
Replies (0)
Login or Join to comment.