Posted by dharam1987 on August 13, 2012 at 9:35am
Question :- How to add dynamic id to UL of a menu rendered by drupal, I have found solutions for the list items, links but nothing to alter the UL. theem_menu_tree doesnt provide any data to identify the menu id, or menu name.
Let me know if anyone has a solution for this.
PS : I have alternative solution, so I am curious if this is possible to override the ul tag and add custom id, class to it based on the menu name, region name etc.
Thanks.

Comments
Easy Way
Hi Dharam ,
you can use theme_links function in template.php file in your theme and you can add id /class in ul,li and a tag .
Ravi
Ravi Drupal Developer
I think I can only edit the anchor tag
Hello Ravi,
Thank you for your reply.
Could you please give an example of what you are saying.
I want to alter the
<
ul someid someclass>
Using theme_item, theme_links I can only alter the
Let me know how the theme_links will help me altering the
<
ul> tag.
Thanks
Dharmendra Patri
Learning never stops, I am no better than you just because I know something which you don't know.Everybody has some special skills which the other person don't have. Never underestimate your self and step forword towards your goals.
try once ..
try once .. theme_menu_link(array $variables) in template.php
theme_links function
example
function ninesixty_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = "
";- $class)) . '>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$fragment = "";
$path = explode("/",$link['href']);
$nid = $path[1];
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '
if (isset($link['href'])) {
if($fragment)
$link['fragment']=$fragment;
if(!empty($link['attributes']['title']))
$link['attributes']['title'] = t($link['attributes']['title']);
// Pass in $link as $options, they share the same keys.
$output .= l(t($link['title']), $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '' . t($link['title']) . '';
}
$i++;
$output .= "
\n";
}
$output .= '
';
}
return $output;
}
Edit In this code you can add class/ID in ul,li and a tag.
Ravi Drupal Developer