Hi guys, I need help in understanding class rewrinting of drupal function theme_links.
I have found lot of solutions on the web but i'm new in php and i cant understand how to do some things.
Basically I need the primary links, the ul id of ma primary links must be nav and the class sf-menu
I have accomplished with this snippet and it works like a charm.
print theme('links', $primary_links, array('id' => 'nav','class' => 'sf-menu'))
My ul has id = nav and class = sf-menu
Now my main problem is one:
i need every tag li with the class -> first-level-li
and every tag a (who belong to the li tag) with the class first-level-link
Now i have this situation:
<li class="menu-504 active-trail first active">
<a href="/" title="" class="active">Home</a>
</li>
What i'm trying to accomplish is:
<li class="first-level-li">
<a href="/" title="" class="first-level-link active">Home</a>
</li>
I have found this snippet but doesn't works well, for example, this part:
// Automatically add a class to each link and also to each LI
doesn't work for me and i have no dk_three on items.
function yourThemeName_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;
// Automatically add a class to each link and also to each LI
if (isset($link['attributes']) && isset($link['attributes']['class'])) {
$link['attributes']['class'] .= 'dk_three ' . $key;
}
else {
$link['attributes']['class'] = $key;
}
// Add first and last classes to the list of links to help out themers.
$extra_class = '';
if ($i == 1) {
$extra_class .= 'first dk_four ';
}
if ($i == $num_links) {
$extra_class .= 'last dk_five ';
}
$output .= '<li ' . drupal_attributes(array('class' => $extra_class . $class)) . '>';
// 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++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
Someone can please help me to make this function? Making examples of code?
Thx a lot
Luke
Comments
Why not use the superfish
Why not use the superfish module?
Because i will to learn how
Because i will to learn how to do this :)