Topic: Menu link to external URL or document rather than a page
I have created a snippet which contains my site navigation. I use a foreach() to display the children for each parent link. Everything is working fine, except now some of my submenus need to have links which either link directly to a document or an external URL. They do not link to actual pages.
Currently, I'm echoing out a <li> and a <a href=""></li>, like so (assuming we're on level 2):
foreach ($this->parent->children() as $menu) { ?>
<li><a href="/<?php echo $dir . '/' . $menu->slug; ?>"<?php if ($sub == $menu->slug) { echo ' class="subselect"'; } ?>><?php echo $menu->title; ?></a></li>
<?php
} // end foreach(the variable $dir above refers to the first array element [1] after I explode() the $_SERVER['REQUEST_URI'] on '/', $sub refers to element[2])
If I created an array of slugs which are to have their links go to docs or external URLS, such as:
$ext_url = array('this_slug', 'that_slug'); // slugs which are supposed to link to external URLs
$pdf = array('pdf_slug'); // slugs which are supposed to link directly to pdfsand then in my foreach, do a conditional like so:
if (in_array($menu->slug, $ext_url)) { ?>
<li><a href="<?php echo $menu->content; ?>" target="_blank"><?php echo $menu->title; ?></a></li>
<?php } ?>where $menu->content were the actual external URL or the document path, would I be on the right track, or is there a much, much, much easier way to do this, such as using a plugin to give me a "PDF" or "external URL" document type I could look for in my foreach?
Last edited by jnish15 (2010-06-30 19:58)

