Jump to content

Recommended Posts

Posted

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

 

Posted

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.

Posted

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

  • Like 2

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