Menu Items Automatically Pointing to New Articles

From Joomla! Documentation

Sometimes a submenu item should point to a new article as soon as the article is written, and this without having to edit the menu.

This can be done in Joomla 1.5 via the latestnews module and an HTML override:

1. Create a latestnews module to list all articles in the category which shall be added to the menu.
The module output can be formatted per stylesheet in exactly the same manner as a 'real' submenu. (Use module style="xhtml" to get a simple <ul> list.)

2. Under 'Menu Assignment' configure this latestnews module to only display when the appropriate main menu item is active.
This pseudo-submenu will show up when the specific main menu item has been selected and it will disappear as soon as another main menu item is selected. Other main menu items may of course contain real submenu item or point to additional latestnews modules.

Now we have a 'pseudo submenu' which looks and behaves like a real submenu.
The only disadvantage is the lack of the "active" attribute which prevents us from visually marking the currently selected submenu item.

To get this work as well, install an HTML override in the template:

3. In the active template's folder create the subfolder structure 'html/mod_latestnews'
(unless your template already contains this override)

4. In this folder 'html/mod_latestnews'. . .

  a) create a file 'index.html'. (copy one from any other folder).

  b) create a file 'default.php'. This is the code which will overrride the standard 'latestnews' output.

The content of 'default.php' is:

<?php // @version $Id: default.php 9718 2007-12-20 22:35:36Z eddieajau $
  defined('_JEXEC') or die('Restricted access');
  if (count($list)){
  $uri = JFactory::getURI()->toString();
  echo '<ul class="latestnews'.$params->get('pageclass_sfx').'">';
  foreach ($list as $item){
    if(strpos($uri, $item->link) === false)
      $act = '';
      $act = ' active';
    echo '<li class="latestnews'.$params->get('pageclass_sfx').$act.'">';
    echo ' <a href="'.$item->link.'">'.$item->text.'</a></li>';
  echo '</ul>';

This checks if the link target is the same as the current page. If yes, it adds the 'active' class attribute. This code could be enhanced (shorter, add additional output style options, prevent the not very likely case that the test gives a wrong positive result, etc.).