I asked this in http://drupal.org/node/106718

The solution is quite simple actually :

In the file includes/themes.inc I have copied the function theme_links { .... } to a new function theme_linksa.

In this function, i have commented out the lines :

$output = '<ul'. drupal_attributes($attributes) .'>';
$output .= '<li class="'. $extra_class . $class .'">';
$output .= "</li>\n";
$output .= '</ul>';

I accept to hear that it's quick and dirty, but it works perfectly :

Now I'm calling my primary links with :

<?php if (isset($primary_links)) { ?>
<?php print theme('linksa', $primary_links, array('class' =>'links primary-links')) ?>
<?php } ?> 

Before it was called with :

<?php if (isset($primary_links)) { ?>
<?php print theme('links', $primary_links, array('class' =>'links primary-links')) ?>
<?php } ?> 

Comments

criz’s picture

but why don't you just override the theme_links function? At least I would put your new function in the template.php file. Would be cleaner I guess...

cheers,
chris
________________________
Austrian Drupal Usergroup

________________________
Drupal Austria Association

jmary’s picture

Simply because I still don't have a full understanding of the whole system structure.

I just kept pragmatic here. It works, I adopt it, and it works for all the themes, not only the one I want to use.

--
Julien MARY

Chill35’s picture

You did well NOT to override the function, as it would probably have broken other things. For example, the primary links use that function, hence they are an unordered list : so THAT would probably be broken.

I used the exact same solution as you have, and it really is the best.

Caroline

Chill35’s picture

However you can move your extra theme function in template.php

Here's my code :

In template.php I added this function. It is almost like the original function, only slighlty modified... not like yours I realize now, please take a look :


function phptemplate_links_in_node($links, $attributes = array('class' => 'links'), $delimiter='') {

  $output = '';
  $start = false;

  if (count($links) > 0) {
    $output = '<div'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
    
      // Automatically add a class to each link
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
      }
      else {
        $link['attributes']['class'] = $key;
      }

      // Add delimiter
      if ($start) { $output .= " $delimiter "; }

      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

      $i++;
      $start = true;
    }

    $output .= '</div>';
  }

  return $output;
}

And I call that function in node.tpl.php :

<?php if ($taxonomy): ?>
<div class="terms">
<?php print theme('links_in_node', $taxonomy, array('class' => 'links inline'), ' | '); ?></div><br />
<?php endif;?>

<?php if ($links): ?>
<div class="links"><?php print theme('links_in_node', $node->links, array('class' => 'links inline'), ' | '); ?></div>
<?php endif; ?>
</div>

It's clean and Drupalers-approved as the core remains untouched.

Caroline

Chill35’s picture

Your function's name is theme_linksa.

You can move it to template.php and rename it : phptemplate_linksa...

And in node.tpl.php, you can call it this way : theme('linksa', ... )

Good luck :)

Chill35’s picture

Man... I am so tired.

So you have used this trick to change the HTML of the primary links.

So I meant to say that : by overriding the themeing function you would then have broken the themeing of links in nodes and taxonomy terms... among other things.

We just used the same trick for different things (and done so slightly differently) : you for primary links, and me for links and taxonomy terms in nodes. You in theme.inc, and me in template.php.

:) Sorry about that.

ubersoft’s picture

.primary-links li {
list-style: none;
}

Shouldn't that do what you want?

ekkay’s picture

I tried your suggestion but it doesn't work. :(

Can somebody just make a template for version 5.x where the primary links are listed vertically? Thanks so much. I have been spending hours trying to figure out how to do it. I have already tried your suggestions (many thanks for those), but still the effort is futile.

ekkay’s picture

Hey, thanks. :)
This works well for me.
I don't mind redundancy. For now, I prefer function over form.

I just hope that someone can show us a more elegant way of solving this problem soon.