Alamut Posted Tuesday at 01:57 PM Share Posted Tuesday at 01:57 PM Hello, is it possible to remove or hide the links of the parent pages? Example: /category/car/car-category/internal/product-1/ I would like a link similar to this in the frontend: /car/internal/product-1/ I tried with hooks and active urlsegment, but nothing changes How can I do it? Thanks Link to comment Share on other sites More sharing options...
da² Posted Tuesday at 03:29 PM Share Posted Tuesday at 03:29 PM (edited) Hi @Alamut, You can do this with URL hook: https://processwire.com/blog/posts/pw-3.0.173/#telling-processwire-what-page-to-render Another solution is to create a template and a unique page "product-sheet" to display all your products. So the URL will always be the same except for the product ID. Quote /product-sheet/1234/ Edited Tuesday at 03:30 PM by da² Link to comment Share on other sites More sharing options...
Alamut Posted yesterday at 07:53 AM Author Share Posted yesterday at 07:53 AM Hi, there are already pages that display the products of that category, my question was if it is possible, for the products, you do not have in the url the references to the parent categories, I tried to use the url hooks but without success, can someone help me? Thanks. Link to comment Share on other sites More sharing options...
virtualgadjo Posted yesterday at 09:25 AM Share Posted yesterday at 09:25 AM Hi, even if i would not recommend what you are looking for being a great fan of structure in the url and the use of page reference when it comes to products/posts and so on categories, i think you would need two hooks the first one to create the wanted url on the fly, the now well known @WillyC's one let'assume your products have a template named... product 😀 $pages->addHookAfter('Page::path', null, 'hookPagePath'); function hookPagePath(HookEvent $e) { $page = $e->object; if($page->template == 'product') $e->return = "/car/internal/$page->name/"; } this will automatically generate the url but, big bvut, clicking on the link would lead to a 404, thus now comes the hook in the page @da² is speaking about $wire->addHook('/car/internal/(.*)', function($event) { $name = $event->arguments(1); $product = $event->pages->get("template=product, name=$name"); if($product->viewable()) return $event->pages->get($product->id); }); and this tells pw what is the real page behind this fale url (both hooks, in that order, in your ready.php file) written on the fly so you may have to adapt to your templates and situation (and, maybe also use a more restrictive regex...) something more, this will only work if each product is under one category when the use of page reference would allow a product to belong to more than one have a nice day 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now