Assign id to primary-links

Joined: 06/25/2007

Hey guys,

I was wondering how I might output my primary-links menu with a specific id asigned to the top level ul.

I am trying to achieve the following:

<ul id="main_nav">
<li>Home</li>
<li>Products
<ul>
<li>widget 1</li>
<li>widget 2</li>
</ul>
</li>
<li>Contact</li>
</ul>

I haven't found a clear explanation of what to put in either the template.php file or my page.tpl.php file to achieve this.

I have tried manipulating this code

<?php print menu_tree($menu_name = 'primary-links'); ?>

and this:
<?php
$my_menu
= menu_tree('primary-links');
$my_menu = str_replace("leaf", "", $my_menu );
$my_menu = str_replace("active-trail", "", $my_menu );
$my_menu = str_replace("menu", "", $my_menu );
$my_menu = str_replace("active", "", $my_menu );
$my_menu = str_replace("expanded", "", $my_menu );
$my_menu = str_replace(" class=\"\"", "", $my_menu );
print
$my_menu;
?>

Without much luck.

Any help is appreciated!
Thanks

Rick
"For what will it profit a man if he gains the whole world, and loses his own soul?" (Mark 8:36 NKJV)

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
theme_links

<?php
 
print theme('links', $primary_links, array('id' => 'my_id_name'));
?>

See http://api.drupal.org/api/function/theme_links/6

Matt Farina
Geeks and God Co-Host
www.innovatingtomorrow.net
www.mattfarina.com

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

Joined: 06/25/2007
Nested List Items

Thanks for your reply Matt. This code works great, my only question is how would I output the full tree with the nested list items?

I tried combining what you gave me with the code I was using to print the full list like so...

<?php
   
print menu_tree($menu_name = 'primary-links', array('id' => 'my_id_name'));
?>

This gives me the full list with the nested menu items but doesn't assign an id to the top level ul. Is there something I'm missing?

Rick
"For what will it profit a man if he gains the whole world, and loses his own soul?" (Mark 8:36 NKJV)

Sam
Sam's picture
Can anyone answer rickhocutt ???

I have been searching far and wide for a way to theme menus in Drupal 6.

How do you output the FULL tree and select UNIQUE id's for each <ul> ? It seems no one can answer this.

Someone must know the answer???

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
theme function

@rickhocutt looking at the code you posted I notice it's not following the api for menu_tree. Using my trust http://api.drupal.org and the function I would do something like...

<div id="some-name">
<?php print menu_tree('menu_name'); ?>
</div>

Then I would reference the specific uls via the wrapper div.

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

Joined: 12/16/2007
That's what i did...

That's what I did, and it works fine for nested css menus. Just wrap the menu in a div, and use standard parent/child selectors to reference it.

div#some_name ul {
/* first level css code*/
}

div#some_name ul ul {
/* second level css code */
}

Since I'm not a javascript guy, I don't know if this would work if you wanted to manipulate the menu via ajax or javascript. Someone smarter than I would need to answer that.

Tony