Hi all,

I dont like starting threads that already exist but i am stuggling to understand why i cant get span tags to be applied to my primary links.
I see this post: http://drupal.org/node/112761 and thought this must be it but when i follow these instructions my primary links disapear altogether!

I want to change my primary links from:
<li class="menu-197"><a href="#" title="">Link1</a></li>

to:

<li class="menu-197"><span><a href="#" title="">Link1</a></span></li>

I have copied the theme_links function from theme.inc and pasted it in the template.php file within my theme directory.

I have chnaged this line:
function theme_links($links, $attributes = array('class' => 'links')) {
to:
function phptemplate_primary_links($links, $attributes = array('class' => 'links')) {

and changed template.php

Chnaged this:
if (isset($primary_links)) :

print theme('links', $primary_links, array('class' => 'links primary-links'))

endif;

to this:
if (isset($primary_links)) :
print theme('primary_links', $primary_links, array('class' => 'links primary-links'))
endif;

That is all i have chnaged and the primary links do not show at all. I must be doing a typo but i cant grasp what error has been made.

Can you help?

Thanks in advance

M

Comments

pixelite’s picture

Whenever you add a new function to your template.php file, you need to clear your theme registry.
There could be other issues as well, just checking that you've done this.

nivlem’s picture

I didnt know that. thank you. i will look into how i do this and feedback.

Thanks

nivlem’s picture

Ok i have cleared my theme registry and the primary links still dont show.

I followed this instruction:
On the "Administer > Site configuration > Performance" page, click on the "Clear cached data" button

Any ideas why my primary links dont show after following the above ?

Thanks

nivlem’s picture

Ok i seem to be getting somewhere in that i have now managed to get span to be in my primary links. The problem i have is the <span> is wrapping around the wrong element.

Currently the <span> is wrapped around the link text in the anchor tag:

<li class="menu-197"><a href="#" title=""><span>Link1</span></a></li>

i want to wrap the <span> around the anchor tag itself, like this:

<li class="menu-197"><span><a href="#" title="">Link1</a></span></li>

Here is the template.php file thats in my themes folder:

<?php 
function theme070_menu_local_task($link, $active = FALSE) {
  return '<li '. ($active ? 'class="active" ' : '') .'><span><span>'. $link ."</span></span></li>\n";
}
//
/**
 * Return a themed set of links.
 *
 * @param $links
 *   A keyed array of links to be themed.
 * @param $attributes
 *   A keyed array of attributes
 * @return
 *   A string containing an unordered list of links.
 */
function phptemplate_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;
}
?>

And here is my page.tpl.php page:

<?php
// $Id: page.tpl.php,v 1.25 2008/01/24 09:42:53 goba Exp $
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language->language ?>" xml:lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
  <title><?php print $head_title ?></title>
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <?php print $head ?>
  <?php print $styles ?>
  <?php print $scripts ?>
  
</head>
  
<body>
	<div id="main">
    	<div class="border-bot">
        	<div class="corner-top-left">
            	<div class="corner-top-right">
                	<div class="corner-bot-left">
                    	<div class="corner-bot-right">
                        	<table width="100%">
                                <tr>
                                    <td width="100%" class="header">
                                        <table width="100%">
                                          <tr>
                                            <td width="100%" style="height:37px;">
                                            	<table width="100%">
                                                    <tr>
                                                        <td>
															<?php if (isset($primary_links)) : ?>
                                                                <div class="pr-menu">
                                    <?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
                                                                    <br class="clear" />
                                                                </div>
														<?php endif; ?>	 
														</td>
                                                    </tr>
                                                </table>
                                            </td>
                                          </tr>
                                          <tr>
                                            <td width="100%" style="height:51px;">
                                                <?php if ($breadcrumb != ""): ?>
													<?php print $breadcrumb ?>
                                                <?php endif; ?>
                                            </td>
                                          </tr>
                                          <tr>
                                            <td width="100%" style="height:230px;">
                                                <?php if ($logo) : ?>
                                                    <a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><img src="<?php print($logo) ?>" alt="<?php print t('Home') ?>" border="0" class="logo" /></a>
                                                <?php endif; ?>
                                                
                                                <?php if ($site_name) : ?>
                                                    <h1 class='site-name'><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><?php print $site_name ?></a></h1>
                                                <?php endif; ?>
                                                
                                                <?php if ($site_slogan) : ?>
                                                    <div class="slogan"><?php print($site_slogan) ?></div>
                                                <?php endif;?>
                                            </td>
                                          </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="cont-row">
                                        <table width="100%" >
                                            <tr>
                                            <?php if ($left != ""): ?>
                                                <td width="207" bgcolor="#efefef">
                                                    <div class="left2">
                                                        <?php if ($left != ""): ?>
                                                            <table width="100%">
                                                              <tr>
                                                                <td width="100%">
                                                                    <?php print $left ?>
                                                                </td>
                                                              </tr>
                                                            </table>
                                                        <?php endif; ?>
                                                    </div>
                                                </td> <?php endif; ?>
                                                <td width="">
                                                    <div class="cent">
                                                        <?php if ($mission != ""): ?>
                                                            <div id="mission"><?php print $mission ?></div>
                                                        <?php endif; ?>
                                                                    
                                                        <?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
                                                        <?php if ($title != "Forums"){?>
                                                        <?php if ($title): print '
                                                            <h2'. ($tabs ? ' class="with-tabs title"' : '') .'>'. $title .'</h2>
                                                        '; endif; ?>
                                                        <?php }?>
                                                        <?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
                                                        <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
                                                                         
                                                        <?php if ($show_messages && $messages != ""): ?>
                                                            <?php print $messages ?>
                                                        <?php endif; ?>
                                                    
                                                        <?php if ($help != ""): ?>
                                                            <div id="help"><?php print $help ?></div>
                                                        <?php endif; ?>
                                                    
                                                          <!-- start main content -->
                                                        <?php print $content; ?>
                                                    </div>
                                                </td>
                                                <?php if ($right != ""): ?>    
                                                <td width="207" bgcolor="#efefef">
                                                    <div class="right2">
                                                        <?php if ($right != ""): ?>
                                                            <table width="100%" class="bg-col">
                                                              <tr>
                                                                <td width="100%">
                                                                    <?php print $right ?>
                                                                </td>
                                                              </tr>
                                                            </table>
                                                        <?php endif; ?>
                                                    </div>
                                                </td>    <?php endif; ?>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="footer">
		<?php if ($footer_message || $footer) : ?>
            <span><?php print $footer_message;?></span>
        <?php endif; ?>
    </div>
<?php print $closure;?>
</body>
</html>

Does anyone know how i wrap the <span> around the anchor tag?

Thanks in advance.

M

MJD’s picture

I think it's this line

$output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link)

the "l" is the link command that generate the anchor tags so the spans should be outside that bit!

e.g.

$output .= '<span>'.l( $link['title'] , $link['href'], $link).'</span>'

nivlem’s picture

Excellent! that's done the trick!

Thanks

cygii’s picture

How can I change code for this:

<li><a href="#">

		<img src="##.gif" alt="" />

		<span>TEXT</span>

	</a></li>

?