2

I'd like to include a notification "!" in my main menu when there is a new blog post. The blog page have already set up Recent order.

"!" will disappear after click - or disappear for a few days - whatever is easiest.

I have tried this link : - https://stackoverflow.com/questions/22638618/main-menu-notification-if-there-is-an-article-update-joomla-2-5

but unfortunately it doesn't work.

Does anyone have an idea on how to solve this?

1

The code from the answer you linked to should work with a couple of changes.

  1. Override mod_menu by copying modules/mod_menu/tmpl/default_component.php to templates/YOURTEMPLATE/html/mod_menu/default_component.php
  2. Add the following code right before if ($item->menu_image):

    if($item->query['option']=='com_content' && $item->query['view']=='category' ){
      $date=date("Y-m-d",strtotime("-1 week")); //articles from up to 1 week ago
      $query="select id from #__content where state=1 and catid="
        .intval($item->query['id'])
        ." and publish_up >= '". $date . "'";
        $db=JFactory::getDbo();  
        $db->setQuery($query);
    if(count($db->loadAssoc())) $item->title.=' !';  
    }
    

Any Category Blog menu items will display an exclamation mark if there are (published) articles from within the last week.

Note: this only works if you're using mod_menu to display your menu. Some templates (e.g. from RocketTheme and Shape5) uses their own menu system by default, but this can usually be changed in template settings).

  • Brilliant! At first it didn't work, when I went to template setting, ensure its off, it overwritten php again, so I forced update it again, now is working. 'code' $item->query['view']=='category' ) Is that category you can change it to specific name like 'help', not all menu? I got menus ID = 15, and 20, would that goes to catid=15, 20? Do you know how to expire "!" after clicked once? – JamesDC Oct 28 '15 at 11:13
  • is it possible for the notification to remain for one week unless it is clicked? if it is clicked will the notification disappear? @johanpw – JamesDC Nov 2 '15 at 10:43
  • @JamesDC I'm sure it's possible, but I can't give you a simple answer. You'd have to create a code that checks if the current (logged in) user has read the article, and store this information in the database. Or maybe set a cookie when user X reads article Y. [This post] has a similar question with a couple of ideas. – johanpw Nov 2 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.