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 pdfs

and 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)

Thumbs up

2

Re: Menu link to external URL or document rather than a page

jnish15 wrote:

... 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?

Well -- it looks like it works! But it also seems a bit labour-intensive. Won't you have to set up the pdf and external arrays manually?

You could (probably?) automate this to some degree by using the Redirector plugin. It's a very useful tool (IMO!), and could probably be cajoled into doing what you're after here.

(Welcome to the Wolf forms, btw! wink )

Re: Menu link to external URL or document rather than a page

Or check out my menu management plugin.

HTH!

4

Re: Menu link to external URL or document rather than a page

snsmurf wrote:

Or check out my menu management plugin.

Doh! Hadn't clocked that mbMenu handles external links! (Sorry, smurfy!)

(Actually, strategic use of page parts could probably automate this fairly fully ... couldn't it?)

Re: Menu link to external URL or document rather than a page

Hi David,

Thank you for the welcome and reply.

Yes, using the hack idea I posted would require me to build the "exception" arrays (for external URLs and document paths) manually. Not ideal.

Thank you for the resource, I'll check it out.

Thumbs up

Re: Menu link to external URL or document rather than a page

snsmurf wrote:

Or check out my menu management plugin.

HTH!

This looks even more promising, thanks snsmurf

Thumbs up

7

Re: Menu link to external URL or document rather than a page

mbmenu doesn't work for me, I'm using sqlite db (I do not know if that matter)

Fatal error: Call to a member function execute() on a non-object in /path/public_html/wolf/Framework.php on line 805

Thumbs up