Hi,

I would like to change the first level links to show title in the link as text:

From:
Frontpage

To
Frontpage
TITLE

I have tried to change theme_nice_menu_build, but with no succes.

Thanks for great module
Bo :-)

Comments

arlind’s picture

This is the code:

From:
<a class="active" title="TITLE" href="/" rel="nofollow">Frontpage</a>

To
<a class="active" title="TITLE" href="/" rel="nofollow">Frontpage<br />TITLE</a>

:-) Bo

arlind’s picture

Status: Active » Fixed

Did some preg replacements :-) Bo

function phptemplate_nice_menu_build($menu) {
  $output = '';

  foreach ($menu as $menu_item) {
    $mlid = $menu_item['link']['mlid'];
    // Check to see if it is a visible menu item.
    if ($menu_item['link']['hidden'] == 0) {
      // Build class name based on menu path
      // e.g. to give each menu item individual style.
      // Strip funny symbols.
      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
      // Convert slashes to dashes.
      $clean_path = str_replace('/', '-', $clean_path);
      $path_class = 'menu-path-'. $clean_path;
      // If it has children build a nice little tree under it.
      if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
        // Keep passing children into the function 'til we get them all.
        $children = theme('nice_menu_build', $menu_item['below']);
        // Set the class to parent only of children are displayed.
        $parent_class = $children ? 'menuparent ' : '';
	
	// add title to link text
	$linktitle = theme('menu_item_link', $menu_item['link']);
	$linktitle = preg_replace("/<a(.*)title=\"([^\"]*)\"(.*)>(.*)<\/a>/is","<a$1title=\"$2\"$3>$4<span class=\"menutitle\">$2</span></a>",$linktitle, 1);
	
        $output .= '<li id="menu-'. $mlid .'" class="'. $parent_class . $path_class .'">'.$linktitle;
	
	// Clean titles from children
	$children = preg_replace("/<span class=\"menutitle\">.*?<\/span>/is","",$children);	
	
        // Build the child UL only if children are displayed for the user.
        if ($children) {
          $output .= '<ul>';
          $output .= $children;
          $output .= "</ul>\n";
        }
        $output .= "</li>\n";
      }
      else {
	// add title to link text
	$linktitle = theme('menu_item_link', $menu_item['link']);
	$linktitle = preg_replace("/<a(.*)title=\"([^\"]*)\"(.*)>(.*)<\/a>/is","<a$1title=\"$2\"$3>$4<span class=\"menutitle\">$2</span></a>",$linktitle, 1);
	
        $output .= '<li id="menu-'. $mlid .'" class="'. $path_class .'">'. $linktitle .'</li>'."\n";
      }
    }
  }
  return $output;
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.