Sometimes we would like to have a submenu item point to a new article as soon as the article is written, and this without having to edit the menu (see post Adding Articles Automatically to 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 the articles in the category which we want to add to the menu.
The module's output can be formatted per stylesheet in exactly the same manner as a 'real' submenu. (Use module style="xhtml" to get a simple <ul> lists.)
2. Under 'Menu Assignment' configure this latestnews module to only display when the appropriate main menu item is active.
This pseudo-submenu will then 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 still contain real submenu item.
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 has this override)
4. In this folder 'html/mod_latestnews'...
a) create a file 'index.html'. (Just 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:
Code: Select all
<?php // @version $Id: default.php 9718 2007-12-20 22:35:36Z eddieajau $
defined('_JEXEC') or die('Restricted access');
//rjo 2008.07.15, rewrite to identify which article is active.
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 = '';
else
$act = ' active';
echo '<li class="latestnews'.$params->get('pageclass_sfx').$act.'">';
echo ' <a href="'.$item->link.'">'.$item->text.'</a></li>';
}
echo '</ul>';
}
?>
I guess this could be enhanced (shorter, add other output style options, prevent the not very likely case that the test gives a wrong positive result, etc.).
Hope that helps