Customising the primary and secondary links

Description

These examples illustrate how you customise the default layout of primary or secondary links.

Notes

Drupal 4.6 / 4.7

Primary links snippet:

<div id="navigation">
<?php if (is_array($primary_links)) : ?>
<ul id="main-nav">
<?php foreach ($primary_links as $link): ?>
<li><?php print $link?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

Secondary links snippet:

<div id="navigation">
<?php if (is_array($secondary_links)) : ?>
<ul id="main-nav">
<?php foreach ($secondary_links as $link): ?>
<li><?php print $link?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

Drupal 5.0

In 5.0, $primary_links is no longer an array of HTML formatted anchors. Instead each primary link is an array of link attributes. To make it more confusing, one of these attributes, href, can have non-uri values, like <front>. You can see how I handled that exception below, but there may be others.

This is only one way to do this. There are probably better ways using theme engines.

Primary links snippet:

<div id="navigation">
<?php if (is_array($primary_links)) : ?>
<ul id="main-nav">
<?php foreach ($primary_links as $link): ?>
<li><?php

$href
= $link['href'] == "<front>" ? base_path() : base_path() . $link['href'];
print
"<a href='" . $href . "'>" . $link['title'] . "</a>";

?>
</li>

<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

Secondary links snippet:

<div id="navigation">
<?php if (is_array($secondary_links)) : ?>
<ul id="main-nav">
<?php foreach ($secondary_links as $link): ?>
<li><?php

$href
= $link['href'] == "<front>" ? base_path() : base_path() . $link['href'];
print
"<a href='" . $href . "'>" . $link['title'] . "</a>";

?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

 
 

Drupal is a registered trademark of Dries Buytaert.