Automatically add a submenu item pointing to a new article

Forum closed, please submit your tips and tricks to: http://docs.joomla.org/Category:Tips_and_tricks
Locked
rjo
Joomla! Intern
Joomla! Intern
Posts: 59
Joined: Wed May 23, 2007 7:37 pm

Automatically add a submenu item pointing to a new article

Post by rjo » Tue Jul 22, 2008 1:12 am

Hello,
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>';
 }
?>
This checks if the link target is the same as the current page. If yes, it adds the 'active' class attribute.
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

User avatar
brad
Joomla! Master
Joomla! Master
Posts: 13272
Joined: Fri Aug 12, 2005 12:38 am
Location: Australia
Contact:

Re: Automatically add a submenu item pointing to a new article

Post by brad » Tue Jul 22, 2008 1:14 am

Brilliant..

Get this in here: http://docs.joomla.org/Category:Tips_and_tricks people need to see this.

BTW did you see this: http://theartofjoomla.com/magazine/arti ... nique.html


Locked

Return to “Submit Your Suggested Tips & Tricks to Docs.joomla.org now please.”