Good Morning All --

I'm having a problem theming a secondary menu on a Drupal 7 site. I have a functioning Drupal 6 site using the following code in the template.php file to theme a menu on the left side of my page:

<?php
/**
* Returns the themed menu tree.
*/
function phptemplate_menu_tree($menu_name = 'secondary-menu') {
  global
$base_path;
  static
$menu_output = array();
 
$output = '';
 
$output .= '<!--[if IE]><div id="usingIE"><![endif]-->';
 
$output .= '<ul class="nav-first">';
  if (!isset(
$menu_output[$menu_name])) {
   
$tree = menu_tree_page_data($menu_name);
    foreach(
$tree as $link) {
      if(
$link['link']['href'] == '<front>') {
       
$link['link']['href'] = 'home';
      }
     
// Create first level link.
     
if($link['link']['href'] == $_GET['q']) {
       
$output .= '<li class="active">';
      }
      else {
       
$output .= '<li>';
      }
     
$output .= '<a href="' . $base_path;
     
$output .= $link['link']['href'];
     
$output .= '">';
     
$output .= '<span class="t"><em> </em></span>';
     
$output .= '<strong>' . $link['link']['title'] . '</strong>';
     
$output .= '<span class="b"><em> </em></span>';
     
$output .= '</a>';
     
$output .= '</li>';
     
// Check to see if main level has children.
     
if(($link['link']['has_children'] > 0) && ($link['below'] > 1)) {
       
$sub_menu = array();
       
$sub_menu = $link['below'];
       
$output .= '<ul class="nav-second">';
        foreach(
$sub_menu as $p) {
         
// Create second level link.
         
$output .= '<li><a href="' . $base_path;
         
$output .= $p['link']['href'];
         
$output .= '">';
         
$output .= '<strong>' . $p['link']['title'] . '</strong>';
         
$output .= '</a>';
         
$output .= '</li>';
        }
       
$output .= '</ul>';
      }
    }
   
$output .= '</ul>';
   
$output .= '<!--[if IE]></div><![endif]-->';
   
$menu_output[$menu_name] = menu_tree_output($tree);
  }
 
//return $menu_output[$menu_name];
 
return $output;
}
?>

This code generates HTML that looks like this:

<strong>My Education</strong><span class="b"><em> </em></span></a></li><ul class="nav-second"><li><a href="/business"><strong>Business</strong></a></li><li><a href="/career"><strong>Career Center</strong></a></li><li><a href="/education"><strong>Education</strong></a></li><li><a href="/sbsc"><strong>Social & Behavioral Sciences</strong></a></li><li><a href="/sps"><strong>SPS</strong></a></li></ul>

I am now migrating this Drupal 6 site to 7 and am trying to replicate this same menu in the new site - without much luck.

I pasted the above phptemplate functions into the template.php file for the theme I'm using on my 7 site.

The same snippet of HTML on the new site looks like this:

<ul class="menu"><li class="first leaf menu-mlid-1121"><a href="/home">Home</a></li>
<li class="expanded active-trail active menu-mlid-1107"><a href="/my-education" class="active-trail active">My Education</a><ul class="menu"><li class="first leaf menu-mlid-1111"><a href="/business" class="sidebar nav-second">Business</a></li>
<li class="leaf menu-mlid-1112"><a href="/career" class="nav-second">Career Center</a></li>
<li class="leaf menu-mlid-1114"><a href="/SPS">SPS</a></li>
<li class="last leaf menu-mlid-1113"><a href="/sbsc">Social &amp; Behavioral Sciences</a></li>
</ul></li>
<li class="collapsed menu-mlid-1108"><a href="/walsh-life">My Walsh Life</a></li>
<li class="leaf menu-mlid-1109"><a href="/my-training">My Training Center</a></li>
<li class="last leaf menu-mlid-1110"><a href="/my-resources">My Resources</a></li>
</ul></div>
  </div>

Right now, my sub menu links look exactly the same as the parent and that is not what I want. It looks to me like the code I placed in the template.php file is not being recognized. And I'm not sure how to go about getting it to work properly within template.php or perhaps accomplishing the same another way.

Ideas and guidance on this issue would be appreciated.

Thank you!

+ Chris

Comments

Why don't you use Drupals menu functionallity? I don't see the benefits of this sollution.
Building a menu with Drupal you will be able to get this structure in HTML.
All you need to do is build your own logic from your theme with CSS (maybe with some jQuery).

Hi absoludo --

I'm not opposed to that at all. I'm trying to replicate what I already have. How I get there really makes no difference to me. In fact, I believe I've already tried Drupal's menu system, as well as a few other modules for structured menus like Nice Menus and Superfish. I get the same problem where the same style that I have for the parents is being applied to the children and I can't seem to get my changes recognized.

Ah, I guess I did not read your question correct.
To have different styling on children you can use CSS structure like "ul li ul li" to style children different than their parents.

Can you or anyone else tell me how/where the mlids and a random number are generated and placed in the li class for the menu entries?

I now have a menu in place generated from the Drupal menu system. What I'm seeing though is that when displayed, Drupal is treating my sub menu links as top level and applying the same divs and classes. So, the menu system is working properly in that the sub menu links are displaying on the correct pages, but it is not applying the correct CSS structure.

I'm not sure where/how I should adjust this.

Anyone have any thoughts?

I now have this in place in my template.php

<?php
function framework_menu_link(array $variables) {
 
//unset all the classes
 
unset($variables['element']['#attributes']['class']);
 
$element = $variables['element'];
  if(
$variables['element']['#attributes'])
 
$sub_menu = '';
  if (
$element['#below']) {
   
$sub_menu = drupal_render($element['#below']);
  }
 
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return
'<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
?>

And this in my page.tpl.php:

<?php
        
print theme('links__system_secondary_menu', array(
           
'links' => $secondary_menu,
           
'attributes' => array(
             
'id' => 'secondary-menu',
             
'class' => array('sidebar', 'nav-second'),
            ),
           
'heading' => array(
             
'text' => t('Secondary menu'),
             
'level' => 'h2',
             
'class' => array('element-invisible'),
            ),
          ));
?>

My sub menu links are still the same and its now throwing an error saying $sub_menu is not a recognized variable.

Anyone have any thoughts?

Thanks!

+Chris