Customizing the primary and secondary links
Last modified: August 26, 2009 - 02:53
Description
These examples illustrate how you customize the default layout of primary or secondary links.
Notes
- For use within your page.tpl.php file.
- The example snippets converts your primary/secondary links to an unordered list
- Please discuss or suggest tips at this thread on the forum discussing how to customize primary/secondary links
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>