mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
User avatar
lord_alan
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Jun 28, 2006 5:48 pm
Location: Farnham, Surrey, England.
Contact:

mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by lord_alan » Mon Feb 25, 2008 2:52 pm

I read somewhere that in J1.5 the menu module would add two classes to each <li> element. One being the menu level.

I am attempting to integrate some css for a combined dropline/dropdown menu and I "really" need to be able to assign classes to represent each level of hierarchy.

This is what I am getting currently

Code: Select all

<div class="moduletable_module_class_suffix">
	<ul class="menu_menu_class_suffix" id="_menu_tag_id">
		<li id="current" class="active item1"><a href="..."><span>Home</span></a></li>
		<li class="parent item27"><a href="Itemid=27"><span>Joomla! Overview</span></a>
			<ul>
				<li class="item34"><a href="Itemid=34"><span>What's New in 1.5?</span></a>
					<ul>
						<li class="item53"><a href="Itemid=53"><span>test sub menu</span></a></li>
					</ul>
				</li>
			</ul>
		</li>
...
What I would like is something more like this (note the addition of level(n) to the li class):

Code: Select all

<div class="moduletable_module_class_suffix">
	<ul class="menu_menu_class_suffix" id="_menu_tag_id">
		<li id="current" class="level1 active item1"><a href="..."><span>Home</span></a></li>
		<li class="level1 parent item27"><a href="Itemid=27"><span>Joomla! Overview</span></a>
			<ul>
				<li class="level2 item34"><a href="Itemid=34"><span>What's New in 1.5?</span></a>
					<ul>
						<li class="level3 item53"><a href="Itemid=53"><span>test sub menu</span></a></li>
					</ul>
				</li>
			</ul>
		</li>
...
Does this functionality exist in 1.5 or was I ill-informed? I can't see how to enable it if it does...

Thanks

Alan
Last edited by lord_alan on Mon Feb 25, 2008 8:56 pm, edited 1 time in total.
The Way Out Is Open!
http://www.theopensourcerer.com

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 4:22 pm

I believe the menu heirarchy CSS code works like this. Might be wrong, but believe I have seen this applied in templates like this:

First Level = ul
Second Level = ul ul
Third Level = ul ul ul

Therefore, if it does, break out the "_menu" CSS that contains this code, to three sections:

div.module_menu ul li a:link, div.module_menu ul li a:visited { font-weight: bold }

div.module_menu ul ul li a:link, div.module_menu ul ul li a:visited { font-weight: bold }

div.module_menu ul ul ul li a:link, div.module_menu ul ul ul li a:visited { font-weight: bold }

This also, probably goes with it and needs to be modified for indents, etc. for each ul level:

div.module_menu ul { margin: 10px 0; margin-left: 20px; } [repeat as per above]

Let me know if this information was correct or not, so I'll be able to make note of it in my refrences.
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 4:24 pm

Just checked another template, that does it this way:

table.moduletable_menu ul li ul li a:link,
table.moduletable_menu ul li ul li a:visited,
table.moduletable_menu ul li ul li ul li a:link,
table.moduletable_menu ul li ul li ul li a:visited
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

User avatar
lord_alan
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Jun 28, 2006 5:48 pm
Location: Farnham, Surrey, England.
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by lord_alan » Mon Feb 25, 2008 4:42 pm

Thanks for the reply.

I had an inkling I could do it that way, but I was thinking I'd need to use the child selector construct rather than the descendant. But I'll give that a go when I have a quiet moment! (I will need to re-code someone else's complex CSS...).

It would be "a lot" easier if one could get some class assignment of level within the structure. I found where I read about it before; here: http://www.joomla.org/component/option, ... ,33/p,106/. It is quite an old post so maybe his work got dropped.

Anyway, thanks for the comments and I'll report back my findings.

Cheers

Al
The Way Out Is Open!
http://www.theopensourcerer.com

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 4:50 pm

You can do it by "class=item##" but you would need a CSS for each menu link item, vs. what you want to do with a "level of menu list items" which is probably ul li ul li, etc. and if you did "ul li.item##" you could style an individual menu list item within the sub-list.
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

rjs-s
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Mon Oct 08, 2007 2:56 pm
Location: Olympia, WA
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by rjs-s » Mon Feb 25, 2008 5:33 pm

The parameters of the menu module assigned to your menu will determine how class and id selectors are applied to the menu.

Go to Extensions -> Module Manager
Select your menu by Module Name (i.e. Main Menu) (the Type will be mod_mainmenu)
Module Parameters will provide options for
- Menu Style
Advanced Parameters will provide options for
- Menu Tag ID
- Menu Class Suffix
- Module Class Suffix

The Legacy Parameters are really useful if you are using one of the Legacy "Menu Styles" selected through the Module Parameters.

You can play with different Menu Styles to see which one outputs selectors formatted closest to what you would like (as shown by code in original post) then set the specific classes and selectors throught the Advanced/Legacy Parameters.

-RJ

User avatar
lord_alan
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Jun 28, 2006 5:48 pm
Location: Farnham, Surrey, England.
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by lord_alan » Mon Feb 25, 2008 5:44 pm

Yes, I am aware of that. But there is no obvious way to apply a class attribute to the multiple levels of a menu; as discussed in the original post and the developers blog I liked to in a subsequent post.

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 5:52 pm

Correct! Only a Page Class Suffix is available for sub-menus insomuch as the ul li ul li ul li is a CSS class by itself and can be thusly configured with an additional suffix.
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 5:53 pm

Correct that: WITHOUT an additional suffix.
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

rjs-s
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Mon Oct 08, 2007 2:56 pm
Location: Olympia, WA
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by rjs-s » Mon Feb 25, 2008 6:20 pm

The level definition addressed in the Team Blog post you linked to does exist. There is not a parameter or setting that can be changed to activate it. There is a code modification that you need to apply.

This can be done through template overriding or by changing the core file.

See modules->mod_mainmenu/tmpl/default.php

In the function modMainMenuXMLCallback

Near the end, take this line:

Code: Select all

$node->removeAttribute('level');
and comment it out. It could look like this:

Code: Select all

//$node->removeAttribute('level');
This will change the output of the code when using the "List" Menu Style in Joomla 1.5 menus. My code before was formatted like this:

Code: Select all

<div class="module_module">
<div>
	<div>
		<div>
			<h3>Main Menu</h3>
			<ul class="menu_menu" id="_tag">
				<li class="item1"> <a href="http://localhost:8066/rjs-s/"> <span>Home</span> </a> </li>
				<li class="parent active item27"> <a href="/rjs-s/index.php?option=com_content&view=section&layout=blog&id=4&Itemid=27"> <span>Photo Store</span> </a>
					<ul>
						<li id="current" class="parent active item34"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=25&Itemid=34"> <span>About The Store</span> </a>
							<ul>
								<li class="item54"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=29&Itemid=54"> <span>Finding Your Photos</span> </a> </li>
								<li class="item2"> <a href="/rjs-s/index.php?option=com_content&view=article&id=5&Itemid=2"> <span>Photo License</span> </a> </li>
							</ul>
						</li>
						<li class="item53"> <a href="/rjs-s/index.php?option=com_content&view=category&id=30&Itemid=53"> <span>Buying Your Photos</span> </a> </li>
					</ul>
				</li>
				<li class="item37"> <a href="/rjs-s/index.php?option=com_contact&view=contact&id=1&Itemid=37"> <span>Contact RJ</span> </a> </li>
				<li class="parent item41"> <a href="/rjs-s/index.php?option=com_content&view=section&id=3&Itemid=41"> <span>FAQ</span> </a> </li>
				<li class="item50"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=50"> <span>The News</span> </a> </li>
				<li class="item48"> <a href="/rjs-s/index.php?option=com_weblinks&view=categories&Itemid=48"> <span>Web Links</span> </a> </li>
			</ul>
		</div>
	</div>
</div>
Now the code looks like this:

Code: Select all

<div class="module_module">
<div>
	<div>
		<div>
			<h3>Main Menu</h3>
			<ul class="menu_menu" id="_tag">
				<li level="1" class="item1"> <a href="http://localhost:8066/rjs-s/"> <span>Home</span> </a> </li>
				<li level="1" class="parent active item27"> <a href="/rjs-s/index.php?option=com_content&view=section&layout=blog&id=4&Itemid=27"> <span>Photo Store</span> </a>
					<ul>
						<li level="2" id="current" class="parent active item34"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=25&Itemid=34"> <span>About The Store</span> </a>
							<ul>
								<li level="3" class="item54"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=29&Itemid=54"> <span>Finding Your Photos</span> </a> </li>
								<li level="3" class="item2"> <a href="/rjs-s/index.php?option=com_content&view=article&id=5&Itemid=2"> <span>Photo License</span> </a> </li>
							</ul>
						</li>
						<li level="2" class="item53"> <a href="/rjs-s/index.php?option=com_content&view=category&id=30&Itemid=53"> <span>Buying Your Photos</span> </a> </li>
					</ul>
				</li>
				<li level="1" class="item37"> <a href="/rjs-s/index.php?option=com_contact&view=contact&id=1&Itemid=37"> <span>Contact RJ</span> </a> </li>
				<li level="1" class="parent item41"> <a href="/rjs-s/index.php?option=com_content&view=section&id=3&Itemid=41"> <span>FAQ</span> </a> </li>
				<li level="1" class="item50"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=50"> <span>The News</span> </a> </li>
				<li level="1" class="item48"> <a href="/rjs-s/index.php?option=com_weblinks&view=categories&Itemid=48"> <span>Web Links</span> </a> </li>
			</ul>
		</div>
	</div>
</div>
Now, this doesn't help you too much because the level is defined in an element property rather than a style definition. Let me get back to you in 5 mintues with a fix. ;)

This is kinda fun to play with. Are you familiar with template overriding? I'll attach a new default.php file that will add levelNN to the style definition.

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 6:30 pm

Meee toooo.
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 6:33 pm

Fast question? Can you make it give the Level=# a NAME instead of a number???
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

rjs-s
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Mon Oct 08, 2007 2:56 pm
Location: Olympia, WA
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by rjs-s » Mon Feb 25, 2008 6:39 pm

Using the default.php file attached your menu output will have style definitions added to the class parameter for each li item in the format levelNN.

Sample output:

Code: Select all

<div class="module_module">
<div>
	<div>
		<div>
			<h3>Main Menu</h3>
			<ul class="menu_menu" id="_tag">
				<li class="level1 item1"> <a href="http://localhost:8066/rjs-s/"> <span>Home</span> </a> </li>
				<li class="level1 parent active item27"> <a href="/rjs-s/index.php?option=com_content&view=section&layout=blog&id=4&Itemid=27"> <span>Photo Store</span> </a>
					<ul>
						<li id="current" class="level2 parent active item34"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=25&Itemid=34"> <span>About The Store</span> </a>
							<ul>
								<li class="level3 item54"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=29&Itemid=54"> <span>Finding Your Photos</span> </a> </li>
								<li class="level3 item2"> <a href="/rjs-s/index.php?option=com_content&view=article&id=5&Itemid=2"> <span>Photo License</span> </a> </li>
							</ul>
						</li>
						<li class="level2 item53"> <a href="/rjs-s/index.php?option=com_content&view=category&id=30&Itemid=53"> <span>Buying Your Photos</span> </a> </li>
					</ul>
				</li>
				<li class="level1 item37"> <a href="/rjs-s/index.php?option=com_contact&view=contact&id=1&Itemid=37"> <span>Contact RJ</span> </a> </li>
				<li class="level1 parent item41"> <a href="/rjs-s/index.php?option=com_content&view=section&id=3&Itemid=41"> <span>FAQ</span> </a> </li>
				<li class="level1 item50"> <a href="/rjs-s/index.php?option=com_content&view=category&layout=blog&id=1&Itemid=50"> <span>The News</span> </a> </li>
				<li class="level1 item48"> <a href="/rjs-s/index.php?option=com_weblinks&view=categories&Itemid=48"> <span>Web Links</span> </a> </li>
			</ul>
		</div>
	</div>
</div>
Modification notes to the default.php file:

Line 83 - Reference to the level attribute was left as-is from the core file.
Line 45 - Added relative addition of the parent selector which prevents overriding of Lines 36-42.
Lines 36 : 42 - Added addition of style definition to the class attribute.

I tried adding the file as an attachment but php, txt and rtf are not allowed. Will try something else in a second.

rjs-s
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Mon Oct 08, 2007 2:56 pm
Location: Olympia, WA
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by rjs-s » Mon Feb 25, 2008 6:45 pm

To override the default.php core file with the modified code save the code below in the following directory.

templates/your_template/html/mod_mainmenu/

Code: Select all

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');


if ( ! defined('modMainMenuXMLCallbackDefined') )
{
function modMainMenuXMLCallback(&$node, $args)
{
	$user	= &JFactory::getUser();
	$menu	= &JSite::getMenu();
	$active	= $menu->getActive();
	$path	= isset($active) ? array_reverse($active->tree) : null;

	if (($args['end']) && ($node->attributes('level') >= $args['end']))
	{
		$children = $node->children();
		foreach ($node->children() as $child)
		{
			if ($child->name() == 'ul') {
				$node->removeChild($child);
			}
		}
	}

	if ($node->name() == 'ul') {
		foreach ($node->children() as $child)
		{
			if ($child->attributes('access') > $user->get('aid', 0)) {
				$node->removeChild($child);
			}
		}
	}

	if($node->name() == "li") {
		if($node->attributes('class')) {
			$node->addAttribute('class', $node->attributes('class').' level'.$node->attributes('level'));
		} else {
			$node->addAttribute('class', 'level'.$node->attributes('level'));
		}
	}

	if (($node->name() == 'li') && isset($node->ul)) {
		$node->addAttribute('class', $node->attributes('class').' parent');
	}

	if (isset($path) && in_array($node->attributes('id'), $path))
	{
		if ($node->attributes('class')) {
			$node->addAttribute('class', $node->attributes('class').' active');
		} else {
			$node->addAttribute('class', 'active');
		}
	}
	else
	{
		if (isset($args['children']) && !$args['children'])
		{
			$children = $node->children();
			foreach ($node->children() as $child)
			{
				if ($child->name() == 'ul') {
					$node->removeChild($child);
				}
			}
		}
	}

	if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
		if ($node->attributes('class')) {
			$node->addAttribute('class', $node->attributes('class').' item'.$id);
		} else {
			$node->addAttribute('class', 'item'.$id);
		}
	}

	if (isset($path) && $node->attributes('id') == $path[0]) {
		$node->addAttribute('id', 'current');
	} else {
		$node->removeAttribute('id');
	}
	$node->removeAttribute('level');
	$node->removeAttribute('access');
}
	define('modMainMenuXMLCallbackDefined', true);
}

modMainMenuHelper::render($params, 'modMainMenuXMLCallback');

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by herb200mph » Mon Feb 25, 2008 6:53 pm

rjs-s. NICE. Next multilevel menu project I have, will give this a try.
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

User avatar
lord_alan
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Jun 28, 2006 5:48 pm
Location: Farnham, Surrey, England.
Contact:

Re: mod_mainmenu - no <li class="level#">

Post by lord_alan » Mon Feb 25, 2008 8:07 pm

WOW!

That's great, thanks.

I go off to eat some dinner and put the kids to bed, come back to my PC and there's a solution. ;D

I've just tested the override and it seems to work exactly as described!

Now I can see it working, I'll go and have a decent look at it and see how you've done it. Well cool.

Thanks again,

Alan
The Way Out Is Open!
http://www.theopensourcerer.com

djb
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Thu Nov 23, 2006 1:00 pm
Location: Farnham, Surrey, England

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by djb » Tue Feb 26, 2008 4:11 pm

This might be a horribly obvious question but if I had the following:

<li class="level1 item1"> <a href="http://www.home.com"> <span>Home</span> </a> </li>

How would I refer to this in CSS, would it be .level1 and would that get all the things on that level or would I have to be more specific and put .level1 item1 ?

herb200mph
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3211
Joined: Sun Jun 25, 2006 12:12 am
Location: Salisbury, NC/USA (N. of Charlotte)
Contact:

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by herb200mph » Tue Feb 26, 2008 4:21 pm

ul li.item1 a:option = 1st level

ul li ul li.item# a:option = 2nd level

ul li ul li ul li.item# a:option = 3rd level
http://www.200mphMedia.net
Author: Joomla! 3: Boot Camp book @ Amazon.com

Biomehaniker
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Tue Jul 11, 2006 8:17 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by Biomehaniker » Thu Apr 03, 2008 11:04 am

Hello rjs-s

your code does exactly what I need... great and a BIG thank you :-)

User avatar
lord_alan
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Jun 28, 2006 5:48 pm
Location: Farnham, Surrey, England.
Contact:

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by lord_alan » Thu Apr 03, 2008 11:49 am

Just to sort of finish off this and contribute something back (as I started this thread!), I found I also needed [O.K. wanted] some control over nested <ul> class levels too.

I modified my default.php a bit more so it now creates class names of either "llevel(n)" (yes that is a double "l") or "ulevel(n)" appropriate to the element where (n) is the depth. i.e.

Code: Select all

					
<ul class="menu_dropline">
	<li id="current" class="llevel1 active item1">
        ...
	</li>
	<li class="llevel1 parent item58">
                ....
		<ul class="ulevel2">
			<li class="llevel2 item69">
                        .....
			</li>
			<li class="llevel2 item70">
                        .....
			</li>
			<li class="llevel2 parent item71">
                                .....
				<ul class="ulevel3">
					<li class="llevel3 item75">
                                        ....
					</li>
                                        ... and so on...
The extra code is only a couple of lines that I added inside this section:

Code: Select all

 
if ($node->name() == 'ul') {
          foreach ($node->children() as $child)
          {
             $ln = $child->attributes('level'); //Start of our hack. Create class="ulevel".$ln
             $node->addAttribute('class', 'ulevel'.$ln); //End hack
             if ($child->attributes('access') > $user->get('aid', 0)) {
                $node->removeChild($child);
             }
          }
       }
This is probably not the best way to do it - I'm not really a "coder" so don't flame, just suggest a better way :D

HTH

Al
The Way Out Is Open!
http://www.theopensourcerer.com

User avatar
jade85
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Tue Mar 04, 2008 12:06 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by jade85 » Thu Apr 16, 2009 5:54 pm

Dear Rjs-s,
Thank u so much for the modificaton for mod_mainmodule. this is excatly what i've been searching for all day. Your a live safer
What doesn't kill you makes you stronger!

oussamac
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Sat Jan 05, 2008 9:22 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by oussamac » Sun Apr 19, 2009 9:50 am

Hello every one!
very intresting and cool!
but I have a simpler solution I think :D :

do like this:
- find the follwing code in your legacy.php file (under <yoursite>/modules/mod_mainmenu) around line 111:

Code: Select all

if ($level > 0) {
		$menuclass = 'sublevel' . $params->get('class_sfx');
	}
- change it to:

Code: Select all

if ($level > 0) {
		$menuclass = 'sublevel' .'_'.$level. $params->get('class_sfx');
	}
that's it!

you will now have a new class for every new sublevel, the class's name will be: sublevel_<n> , where <n> is the number of the sublevel (the first is 1, the second is 2 etc...)

don't forgot that your class name may have a suffix if you changed the class suffix in the module properties


P.S. use firebug to se and change the code online without effecting your site, it is a very powerfull addon on Firefox, I can't develop my pages easily without it!

no64
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sun Dec 23, 2007 9:38 am

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by no64 » Mon Apr 20, 2009 2:58 pm

... isn't the "legacy.php" only used if you are setting Joomla 1.5 to legacy mode?

Anyway, this is great, I was searching for these "levels" a lot.
The "Yootheme" people are also using them for the menus and if you are looking into their code you can also see the "ul" also get that class

Is this possible here too?

and I recongnise they have also a better "sorting" of the menu items...

Level 1 contains always "item1 , item2, item3" and so on and
Level 2 starts over with "item1, item2, etc."

How did they do this?
It would be very helpful to have that feature, cause it seems the "normal" behaviour is the items get always the next number regardless in which "level" they are ...

oussamac
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Sat Jan 05, 2008 9:22 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by oussamac » Tue Apr 21, 2009 7:13 am

no64 wrote:... isn't the "legacy.php" only used if you are setting Joomla 1.5 to legacy mode?
OK, maybe you are right.. ;)
no64 wrote: Anyway, this is great, I was searching for these "levels" a lot.
The "Yootheme" people are also using them for the menus and if you are looking into their code you can also see the "ul" also get that class

Is this possible here too?

and I recongnise they have also a better "sorting" of the menu items...

Level 1 contains always "item1 , item2, item3" and so on and
Level 2 starts over with "item1, item2, etc."

How did they do this?
It would be very helpful to have that feature, cause it seems the "normal" behaviour is the items get always the next number regardless in which "level" they are ...
it would be interesting if someone told us how to do..

no64
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sun Dec 23, 2007 9:38 am

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by no64 » Tue Apr 21, 2009 7:25 am

yeees, indeed

User avatar
jade85
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Tue Mar 04, 2008 12:06 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by jade85 » Tue Apr 21, 2009 7:45 am

Hi oussamac,
What do you mean by how to?. This post contains the answer if your are after a menu with a sublevel that haast it's own CSS sublevel class.

you have to make a so called module overide in you template.
See this link for a how to:
http://blog.opensourcenetwork.eu/tutori ... odmainmenu

Then you need to replace te contents of the file
/yourtemplate/html/mod_mainmod/default.php.
With the code that rjs-s posted into te override file.
Hope it helps ;)
What doesn't kill you makes you stronger!

no64
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sun Dec 23, 2007 9:38 am

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by no64 » Tue Apr 21, 2009 8:02 am

jade85...

I think oussamac know "how to" overwrite with the code rjs-s posted and it's working as expected.
I asked for something additional and that was the question "how to do that" :)
no64 wrote:... isn't the "legacy.php" only used if you are setting Joomla 1.5 to legacy mode?

Anyway, this is great, I was searching for these "levels" a lot.
The "Yootheme" people are also using them for the menus and if you are looking into their code you can also see the "ul" also get that class

Is this possible here too?

and I recongnise they have also a better "sorting" of the menu items...

Level 1 contains always "item1 , item2, item3" and so on and
Level 2 starts over with "item1, item2, etc."

How did they do this?
It would be very helpful to have that feature, cause it seems the "normal" behaviour is the items get always the next number regardless in which "level" they are ...

User avatar
jade85
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Tue Mar 04, 2008 12:06 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by jade85 » Tue Apr 21, 2009 3:47 pm

Ow I see I misread ;)
I don't know how to do that. Maybe you can get your hands on the code that Yootheme uses ;)
What doesn't kill you makes you stronger!

no64
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sun Dec 23, 2007 9:38 am

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by no64 » Tue Apr 21, 2009 4:00 pm

I have one out of a theme, but I really can't understand it

User avatar
jade85
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Tue Mar 04, 2008 12:06 pm

Re: mod_mainmenu - no <li class="level#"> [OVERRIDE! FIXED]

Post by jade85 » Tue Apr 21, 2009 4:11 pm

You only need to understand the code if you want to change it.
If the code does what you want it to you can implement it without understanding it ;)
What doesn't kill you makes you stronger!


Locked

Return to “General Questions/New to Joomla! 1.5”