Jump to content

Recommended Posts

Posted

Been using PW for a bit now and so far I've been able to find answers to most of my questions through the forum, but this time I'm drawing a blank. So I have a special use case for sub navigation on my site.

I have global nav which is pretty standard. When you are on a section you have your standard sub-nav. The issue I'm having is, how do I create a sub nav link in a different Section that points to another page and redirects to it. I'm pretty stumped...

Thanks for any help.

Here is an example of what I mean:

Section 1

- s1_child 1

- s1_child 2

Section 2

- s2_child 1

- s2_child 2

- s1_child 1

And this is the code I've been using so far:

<?php
            // Output subnavigation
  	    if($page->path != '/' && $page->rootParent->numChildren > 0) {

            if($page->numChildren >0){
            	foreach($page->children as $child) {
            		$class = $page === $child ? " class='on'" : '';	
            		$str = $child->title;
            		//limiting title on navigation
            		if(strlen($str) > 15 ){
                	$title = substr($child->title, 0, 13)."…";
            		} else {
              		$title = substr($child->title, 0, 15);
            		}
            		
            		echo "<li $class><a href='{$child->url}'>{$title}</a></li>";	
            	}
            } else {
            	foreach($page->siblings as $child) {
            		$class = $page === $child ? " class='on'" : '';
            		echo "<li $class><a href='{$child->url}'>{$child->title}</a></li>";	
            	}
            }

  	}
?>
Posted

Hi Carlos, here is a quick idea -

Create another template called "navigation_alias".

Add a new field of type "Page" called "navigation_redirect". On the Details tab of the field choose : Single page (Page) or empty page (NullPage) when none selected. Leave the "Parent of selectable page" (input tab) empty (do not set). Add this field to the "navigation_alias" template.

Now you can add a page (with template "navigation_alias") to any section and use the page picker to choose where it should redirect.

In your "navigation_alias" php template file simply add a redirect to the selected page. Something like this :

$session->redirect($page->navigation_redirect->url);
Posted

Ok after playing with it for a bit more, an issue cropped up. Seems if I choose a child page of a Section to redirect. It does not save it. But it does save the url if it is a section...  :-\

BTW I'm using the PageListSelect As the Input Field type. SInce it lists children of sections for selection.

Is this a problem with the Page field?

Posted

Double check your field settings. There is known misbehavior with pagelistselect that allows to select pages, but then doesn't save those if they are not allowed. Not sure that this is the case here, but it might be..

Posted

Hey Apeisa, that's exactly what is happening. It lets me select the page and save it. But, when I go back to double check the save, it is blank. I've tried other input field type selectors, but they don't provide child selection. Any Idea how to get around this or maybe a fix? BTW I'm running ProcessWire 2.1.0

Thanks!

Posted

Check your field settings for that page. Make sure that "parent of selectable pages" is unset. If set to 'home' then click 'change' and then 'unselect' home, and save. I'm guessing that's why it's only accepting pages with parent home.

Likewise, make sure that "template of selectable pages" is unset (unless you know you want it).

Posted

Thanks a bunch Ryan! Problem solved. It was because Parent of Selectable Pages was set to Home. This was a good learning experience. Much appreciated with the help :)

Posted

was just testing and that was the problem.

If you select Home as the parent - despite showing all the pages in the site, and allowing you to select any, it will only save the page value if they are direct children of Home which is a bit confusing.

Maybe only show selectable pages (not sub pages) or change the description of the input field settings to something like this :

“Set the parent of the pages that are selectable or leave empty to allow any page in the site to be selected”

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
  • Recently Browsing   0 members

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