Jump to content

Adding external link to main navigation


Spen
 Share

Recommended Posts

I use the following to get a redirect in the frontend to url outside of processwire, in my case to my shopping cart which is not part of processwire, but it can be any url as you can see below.

What I did was add a page that uses a redirect template to the outside url

1- I made a template called redirect.php

In the template I have this code:

<?php 
$url = "https://www.xxx.xx/";
$session->redirect($url);
?>

2 - I added a page which uses the redirect template on the same level as the other pages that appear in the main menu.

Works like a charm for me.

Link to comment
Share on other sites

You could also use either of these methods/modules:

  1. Module Menu Builder - create custom menus, including external links. You decide what will be in it.
  2. Module Jumplinks - just create the pages you want and create redirects within Jumplinks (/old/path -> https://wherever.test/). It's easier and it handles more than redirects - like 404s and counts every click on your redirects.
  • Like 1
Link to comment
Share on other sites

  • 3 years later...

Yet aaanother google search brought me to this forum. I would like to add more elements to navbar. I just dont know how. They appear to be rendered through this thing inside a loop:

if ($child->checkbox == 1) {
new MenuItem([
"page" => $child,
"isSelected" => $child->id == $this->page->id || $this->isParentOfCurrentPage($child),
"clickDisabled" => $this->isClickDisabled($child)
]);
}

But how do I add more items?
I've also  have this comment added by previous dev, but I know not what to do with this:

// top navigation consists of homepage and its visible children
Link to comment
Share on other sites

Hi @Larhendiel,

there appears to be some custom abstraction that is not part of ProcessWire called "MenuItem". There should be a place where these MenuItem objects are used to generate the actual markup ("<a href" etc.). You may be able to just hardcode your external link there, or build something that aligns more closely with the current system. From the look of it, a MenuItem takes a Page object to generate a link, so unless there already is a way to give it an external address, you’ll have to build it yourself. If you need more concrete assistance, please post the class definition of MenuItem and the code that renders the menu markup (please use the code function for this, it’s the button with the "<>" symbols on it).

Link to comment
Share on other sites

  • 6 months later...

Using Rockfrontend + Latte, I was able to add an external link using the navmenu by writing a condition if the page title matched a string:

{* build the menu *}
{foreach $navItems as $item}
<li n:class="$rockfrontend->isActive($item) ? uk-active">
{if $item == $home}
<a href="{$item->url}">Home</span></a>
{elseif $item->title == "MyMenuItem"}
<a href="https://example.com" target="_blank">{$item->title}</span></a>
{else}
<a href="{$item->url}">{$item->title}</span></a>
{/if}
</li>
{/foreach}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...