Hi again. I am trying to get some css image sliding door technique working for my primary menus and am trying to figure out how to get the primary menu to add in a tag around the link title within the primary or secondary menu. It seems that the span tag is set up in the theme.inc file, but is this overridden in the Basic theme? Is there a way to change this within the theme?

Thanks,

Brian

Comments

Status:Active» Needs review

I guess you are talking abut the basic_menu_item function, used to add class to menu items. You could use this to add a span in your menu link.
It's in template.php line 228 in the latest release.
And avoid changing the core files, like theme.inc , but use themes or modules instead.

Yes, I saw that line in the template.php. It seems that the "$link" part on line 238 is what I need to have changed and I am wondering if that $link is defined elsewhere and can be changed. Otherwise, it seems that I can't put the <SPAN> inside of the <A HREF> tags. Let me try to explain.

If I am seeing the code right, the $link part of the fucntion is bringing in the entire <a href>LINKTITLE</a>.

I need that $link part to be <a href><span>LINKTITLE</span></a>. Is that $link defined anywhere else so that I can edit that?

I also noticed that the way the tabs are being called, they include that SPAN tag, so it seems that it is happening for those.

I hope this makes sense.

Thanks again

Brian

Brian,

I had the same problem as you. I'm not sure this is the best way to solve it, but it worked for me.

1. Locate the 'common.inc' file in the 'includes' folder.

2. Open it and scroll down to line 1561. (Drupal 6.10)

3. Replace this:

return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'. ($options['html'] ? $text : check_plain($text)) .'</a>';

4. With the following:

"return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'. '<span></span>'. ($options['html'] ? $text : check_plain($text)) .'</a>';"

5. Save the file and you're good to go!

Hope this helps.
Mike

**NOTE: A word of caution, please be careful when editing any '*.inc' file. Any single mistyped character/ variable can render part or all of your site useless. Use this at your own risk.**

DO NOT HACK CORE.

this is a bad move and will give you a headache when updating your site down the road.

Proper approach would be to use theme function overrides (what couzinhub was mentioning). THere is already a theme function in the template.php which will allow you to add a class to your links. For more information on theme function overrides check the docs here:

http://drupal.org/node/11811

cheers,

Steve

Thanks all. I did a completely different workaround, which is more in my skill set (obviously, its not PHP coding), but I am finding that that only got me to a passable state with this. I would like to try and work through the template.php customization. If I am reading the correctly, the item that I need to customize would be "theme_menu_item_link"

<?php
function theme_menu_item_link($link) {
  if (empty(
$link['localized_options'])) {
   
$link['localized_options'] = array();
  }
  return
l($link['title'], $link['href'], $link['localized_options']);
}
?>

Does anyone know where the tags would be placed? Would it be around the $link['title']? I know these are newbie questions, but I am still learning. It seems that these items are self-contained with no way to get the in between.

Status:Needs review» Fixed

Here is the code that will generate <a href><span>LINKTITLE</span></a> for your links:

function theme_links($links, $attributes = array('class' => 'links')) {
  $output = '';
  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';
    $num_links = count($links);
    $i = 1;
    foreach ($links as $key => $link) {
      $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']) {
        $class .= ' active';
      }
      $output .= '<li class="'. $class .'">';
      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $link['html'] = TRUE;
        $output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link);
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> 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 .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }
      $i++;
      $output .= "</li>\n";
    }
    $output .= '</ul>';
  }
  return $output;
}

***Remember to replace "function theme_links" with the name of your theme i.e. if your theme name is "foo" you should change this line to "function foo_links"

Status:Fixed» Closed (fixed)

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

Many thanks greekgirl831. I finally got around to making the change, and it worked wornderfully! I have so much control now over the sliding doors menu.

Brian

Version:6.x-1.1» 6.x-2.8
Status:Closed (fixed)» Active

Hi again.

I just upgraded to Drupal 6.14 and also updated my Basic theme. It seems the code is no longer working. Has something changed that I need to alter in the function to make it work again? Many thanks.

Status:Active» Closed (fixed)

Why would you upgrade a theme starter ? Basic is not Zen, it doesn't work as a sub-theme, and is not intended that way.
Basic cease to be Basic as soon as you edit it. Don't worry about upgrades. Many things have changed in the latest releases.
Make sure you read the release notes before upgrading anything.

I actually have both the old theme and the new one side-by-side. The problem happened when I upgraded to Drupal 6.14, not with Basic. The tags disappeared right after the upgrade to 6.14 was completed (the older version of Basic stopped displaying the tags too, though I can't be 100% certain that it wasn't something dumb that I did).

I decided that since I couldn't get the tags to work (and given the philosophy of the Drupal community of keeping up-to-date), I decided to see if the later version would accommodate the tags. So I tried on the old version of Basic and the new one. I also happen to like seeing your progress on this fine and simple design. Sorry about that. Also, the site isn't "live" just yet, so I have a little bit of breathing room to get it right.

When you upgrade, make sure to save all the files that you modified. For example, in template.php, you need to add all the custom functions (like the one greekgirl831 posted) to the updated theme.

I'm the one to blame for not mentionning this in the README or even having a documentation online. Am bad at this kind of things :)
Thanks for using Basic !

Thanks, I worked it out finally. Looks like something happened with a name in the code during the upgrade and I just had to fix that, but now all is working. Again thanks. I love the css freedom that the theme provides.

For anyone coming here and looking for greekgirl831's post... greekgirl831 = HelloStephanie. I changed my name. Happy I could help you guys out!

The code posted on #6 only work on primary and secondary links but not other custom menu.

How to add class to custom menu ?

hi, brinosaur was on the right track
In your theme's template.php add this, make sure to change YOURTHEMENAME to your theme name.

<?php
function YOURTHEMENAME_menu_item_link($link) {
  if (empty(
$link['localized_options'])) {
   
$link['localized_options'] = array();
  }
 
$link['localized_options']['html'] = TRUE; //let l function know that our link title includes html
 
return l('<span>'. $link['title'] .'</span>', $link['href'], $link['localized_options']);
}
?>

<?php
function phptemplate_menu_item_link($link)
{
  if (empty(
$link['localized_options'])) {
   
$link['localized_options'] = array();
  }
 
$link['localized_options'] += array('html'=>true);
  return
l('<span>'.$link['title'].'</span>', $link['href'], $link['localized_options']);
}
?>

This will add span tag to Tabs menu too., but not to theme('links', $primary_links,...) calls...

for theme_links, override with phptemplate_links modifying the following code:

<?php
...
      if (isset(
$link['href'])) {
       
// Pass in $link as $options, they share the same keys.
       
$output .= l($link['title'], $link['href'], $link);
      }
...
?>

to
<?php
...
      if (isset(
$link['href'])) {
       
// Pass in $link as $options, they share the same keys.
       
$output .= l('<span>'.$link['title'].'</span>', $link['href'], array_merge($link, array('html'=>true)));
      }
...
?>

working perfectly ! Thank you ...

I have tried every combination I have on this website and otherwise through Google. I am so frustrated that something this simple is this complicated to implement. Will you please just provide the exact instructions on how to implement this, rather than just showing some code strings? Honestly, this is obviously Drupal's biggest drawback. If I use a cms, I want it to be easier than raw code, that's kinda the whole point. Does someone have a sample template.php they can show or something? Note: I am not using a chlid theme or a framework. I converted this from a static site. Perhaps that's my problem.

I appreciate your help and please forgive me if my frustration comes off as rudeness. I really want this to work.

Thanks,

Brentini

brentini - We're you able to solve this? If not, I can give you a hand if you provide some more details on exactly what you are struggling with. You just want to add the tags?

If you are running Drupal 7 you should see the last post on this page:

http://drupal.org/node/1121144

You need to cut and paste that function into the bottom of your template.php file in your theme folder (exclude the opening/closing php tags), and change the word "THEME" to the machine name of your theme. LMK if you have any questions.

Note that the ease of use/documentation issues that you raise are something the Drupal community is really focused on improving.

- Willy

Mike,

your code:
return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'. '<span></span>'. ($options['html'] ? $text : check_plain($text)) .'</a>';

needs to be:
return '<a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'>'.'<span>'.($options['html'] ? $text : check_plain($text)) .'</span>'.'</a>';

That way the encompasses the title, not starting and ending just in front of it.
BTW thanks.

Thanks for your response,

I actually found a different way to do this using jquery. Might I humbly ask, what is the advantage of using the php technique above, over using a javascript technique as in below?

$(document).ready(function(){
  $("#primary-menu li a")
  .wrapInner("<span>" + "</span>");
});

Brentini

Hi,

Brentini where do you put this code ?

About php code of HelloStephanie for exemple, I tryed to apply the modification omn the template.php of the at_biz template but no span appear.

benB - by sheer chance I am looking at this issue and noticed you mentioned at_biz - dude, this is an option in Adaptivetheme, in the theme settings.