Page 1 of 1

need to add a nested submist to menu

Posted: Tue Aug 01, 2006 8:40 am
by bruceg
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a menu which contains the following XHTML code:

Code: Select all

<ul id="subnav">
<li><a href="/press/releases.php">Executive Corner</a></li>

<li><a href="#">Market Numbers</a></li>
<li class="selected"><a href="#">White Papers</a></li>
<li><a href="#">Glossary</a></li>
<li><a href="#">Newsletter</a></li>
<li><a href="#">June 2006</a></li>
<li><a href="#">Case Studies</a></li>

</ul>
the menu is created dynamically with this function/:

Code: Select all

// CREATE SECTION SUBNAV	imginfo = array("link"=>"","path"=>"","width"=>"","height"=>"","border"=>"","alt"=>"","css"=>"");
	function subNav($link,$text,$subNavListInc=false,$imginfo=false){
		if(isset($_SERVER['REQUEST_URI'])){
			$tmp_class = ( ($link == $_SERVER['REQUEST_URI']) || (($link == $_SERVER['SCRIPT_NAME'])) ) ? ' class="selected"' : '';
		}else{
			$tmp_class = ($link == $_SERVER['SCRIPT_NAME']) ? ' class="selected"' : '';
		}
		$return_str = '<li'.$tmp_class.'><a href="'.$link.'">'.$text.'</a>';
			if($subNavListInc){
				$return_str .= "\r\n".$subNavListInc;
			}
		
		if(is_array($imginfo)){
			if($imginfo["link"]){$return_str .= '<a href="'.$imginfo["link"].'">';}
			$return_str .= '<img src="'.$imginfo["path"].'" width="'.$imginfo["width"].'" height="'.$imginfo["height"].'" border="'.$imginfo["border"].'" alt="'.$imginfo["alt"].'" style="'.$imginfo["css"].'" />';
			if($imginfo["link"]){$return_str .= '</a>';}
		}
		
		$return_str .= '</li>'."\r\n";
		return $return_str;
	}
and the the subnav is an include is put together like this:

Code: Select all

<ul id="subnav">
<?php
			echo subnav('/insight/executive.php','Executive Corner');
			echo subnav('/insight/stats.php','Market Numbers');
			echo subnav('/insight/white.php','White Papers');
			echo subnav('/insight/glossary.php','Glossary');
			echo subnav('/insight/newsletter.php','Newsletter');
			echo subnav('/insight/archive/2006_06.php','June 2006');
			echo subnav('/insight/case_studies/palm.php','Case Studies');
?>
</ul>
what I need to adjust is to have something output like this:

Code: Select all

<ul id="subnav">
<li><a href="/press/releases.php">Executive Corner</a></li>

<li><a href="#">Market Numbers</a></li>
<li class="selected"><a href="#">White Papers</a></li>
<li><a href="#">Glossary</a></li>
<li><a href="#">Newsletter</a>
<ul>
<li><a href="#">June 2006</a></li>
</ul>
</li>
<li><a href="#">Case Studies</a></li>

</ul>

so I need a to produce a <ul> and </ul> for one of the menu items. How would I proceed in doing this by adjusting the PHP code above?


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 01, 2006 9:21 am
by RobertGonzalez
So are you trying to loop inside the loop? Like, running the first LI, then if the subnav meets the same criteria as the LI, loop the subs for that LI in the for of another list?

Posted: Tue Aug 01, 2006 9:27 am
by bruceg
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


yea, just create a sublist for one of the li's to create somthing like

[syntax="html"]<ul>
<li>content1</li>
<li>content2</li>
<li>content3</li>
<li>content4
<ul>
<li>subcontent1</li>
<li>subcontent2</li>
<li>subcontent3</li>
</ul>
</li>
</ul>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 01, 2006 9:31 am
by RobertGonzalez
So where is the data coming from? Usually, I set up two tables in my database... one for categories and the other for links within the categories. I pull two arrays from the database, one for cats and one for links. I loop the cat array, then within the cat loop, I loop the link array for matched between the two.

A simple example would be on this website... look at the divisions on the left nav, then how in each division, there are teams for each. It is done in the way I mentioned above.