Find the last menu item when calling mod_mainmenu.php, in Joomla?

Hi EE -

In mod_mainmenu.php,
Joomla Info:
PHP built On:          OpenBSD server_name.com 3.7 GENERIC#431 sparc64
Database Version:       4.0.13
PHP Version:       5.1.4
Web Server:       Apache/1.3.34 (Unix) PHP/5.1.4
WebServer to PHP interface:       apache
Joomla! Version:       Joomla! 1.0.13 Stable [ Sunglow ] 21 July 2007 16:00 UTC
User Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

 I have:

default:  
            // open in parent window
            $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
            break;

I have added the <li>'s, but when the last $mitem comes through I would like to have something like this:

// open in parent window
            if (CONDITON WATCH FOR LAST ITEM )
            {
               $txt = '<li class="last"><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
            } else
            {
               $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
            }
            break;

Is there a global variable floating around, I can watch for or is there a built in function already available or something else? Any help is greatly appreciated.

Thanks -
Wotan1953
wotan1953Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
modcon_jscottConnect With a Mentor Commented:
A basic example of this type of loop could be like so:

$count = count($my_array);
for($i=0;$i<$count;$i++){
    //check to see if there is an item after this one.
    $class = ( ($i<$cont-1) ) ? ' class="last" ' : '';
    $txt = '<li '.$class.'><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>
}

Now it seems as though the $mitem is an object, and I dont know exactly how this object is produced. You should check to see if there is an EOF attribute of that method or you might be able to implement a variation of this example in a while loop when this object is constructed.

It might be easier to do this in javascript after the menu is constructed and the DOM has been loaded. You will need to assign a class name to all of the li elements. Then you will be able to find them pretty easy.

window.onload = function(){
  var list = document.getElementsByTagName('li');
  var len = list.length;
  list[ (len-1) ].className += 'last';
}

This will only work if there is only one set of li elements in your document. If there arent then you will need to search within the list array for the clasName you are interested in.

Hope this helps.....
0
 
wotan1953Author Commented:
Hey Thanks Much modcon_jscott.  I did as you said and went to the function that was packing this object each time. I waited outside the loop and grabbed the value of the last $row->id. Made it a global var $lastmenuitem. And then watched for it up in the main function. If ($menuitem->id == $lastmenuitem) {
do something different}
0
 
wotan1953Author Commented:
Hi Thanks -

First I went to the function that was calling this object ($mitem)

function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) {
    global $menulastid ;
            if (@$children[$id]) {
                  $n = min( $level, count( $indents )-1 );
// echo "Test 06022008c ".count($children[$id])." <br>";
      echo "\n".$indents[$n][0];
                  foreach ($children[$id] as $row) {

                        echo "\n".$indents[$n][1];

                        echo mosGetMenuLink( $row, $level, $params, $open );

.

.
.
}
                  echo "\n".$indents[$n][3];
                  // echo "<br>Row ID Last ".$row->id." Stop<br>";
                  $menulastid = $row->id;
                  
            }
      }

Then as soon as I dropped out of this loop, I set this var - $menulastid. Plus I made it global.

Then when I get back here:

function mosGetMenuLink( $mitem, $level=0, &$params, $open=null ) {
            global $Itemid, $mosConfig_live_site, $mainframe, $numlinks, $menulastid;
            
.
.
.
.
if (($mitem->id) != ($menulastid ))
                        {
                         
           $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'.$mitem->name .'</a></li>';
        } else
        {
           $txt = '<li class="last"><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name.'</a></li>';
        }
                        // $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
                        break;

.
.
.
 }

Works great!

Thanks
0
All Courses

From novice to tech pro — start learning today.