Jump to content

Ignore parent page in URL structure


IkBenBen
 Share

Recommended Posts

Hi all,

I know this has been asked and answered multiple times... but I'm still having a hard time understanding this so forgive me for asking. 

 

In two parts of my website I would like to ignore the parent page and  change the URL structure from:

 

/services/list/page

to 

/services/page

 

and

 

/articles/list/article

to

/articles/article

 

How do I accomplish this?  I'm sure the solution must be really simple. But for me being a beginner PHP coder, I just can't seem to get my head around it.

 

Thanks in advance!

Link to comment
Share on other sites

  • 5 weeks later...

Sorry to bump this thread but its quite related and the thread not too old.

If you have some pages in your site that are just in the footer, like Terms & Conditions and Help, where do you tend to put the pages in your processwire?

For me, it makes sense to have a page called Footer, and make any menu items that will be in the footer be sub-pages of that. Then, I can build a menu from pages with parent=footer.

However, if I do this, my urls will include their parent, eg /footer/help - obviously this is not desirable. I guess I can call footer whatever I want, like /other/help, or /information/help, but the point is more that I don't want the parent to dictate the URL for something that I want to consider a "top level" page (despite its physical location).

I get that there are solutions to fix this in code, but I feel like this is something that should be managed in the CMS. And if not, in this particular circumstance, how would you suggest allowing the administrator to add to the footer menu?

Link to comment
Share on other sites

Just because a page happens to be linked only in the footer it's probably not supposed to be nested in the page tree. ProcessWire does hold pages in a hierarchical structure, which does not necessarily correspond to all the various navigational patterns used throughout the page. I'd just add those pages as "hidden" children of home. Hidden because they're not part of the primary navigation, but the are still direct children of home (think of the breadcrump you'd have for that page). For building the footer menu I'd just hardcode that one in the template or use some of the few menu builder tools available for ProcessWire. 

  • Like 2
Link to comment
Share on other sites

Thanks Lost, 

That may be the answer, that or simply make a template for menu management with a pages selector field, although that would limit my menu so it couldn't include external links... aah...

Do you have a particular recommendation for menu builder? Can't find one that appears maintained.

Link to comment
Share on other sites

Thanks! :P sorry if I appear fussy, the top result, Menu Builder, has a 3.x bug, but I found the pull request that had a fix, and now I'm using that. It solves my problem and is a nice method of menu management going forward anyway. I do personally think a URL should be fully rewriteable in the CMS out of the box, but still happy with this solution :lol:

Edit: just noticed your name from the menu builder I linked, ;) glad I had good things to say!

Link to comment
Share on other sites

Just found this post and learn this technique.

I tried to replicate for a test on this technique

BaiduShurufa_2016-11-30_6-46-52.png

posts is template posts
post is template post

I replicated the code from another post in the _init.php file
 

wire()->addHookBefore('Page::path', function($event) {
  $page = $event->object;
  if($page->template == 'post') {
    // ensure that pages with template 'post' live off the root rather than '/posts/'
    $event->replace = true;
    $event->return = "/$page->name/";
  }
});

If everything is all right, i should access that page with url
http://test.local.net/pw3/post-1/   (pw3 is a subfolder of www root)
it returned 404 page not found.

 

 

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