0

So this might be a little hard to explain, but i will try my best :).

I have a Webshop running woocommerce, and i have multiple categories, with multiple subcategories. One of the pages is setup to look like this, with a little javascript magic, and help from

window.history.pushState

When you press a category the URL will change:

From www.webshop.com/slug/
To   www.webshop.com/slug/category1

Pressing a category will bring up all the subcategories (see illustration again), then pressing one of the subcategories will change the URL:

From www.webshop.com/slug/category1  
To   www.webshop.com/slug/category1/subcategory1

This is all fine and great, and works exactly as its supposed to - but if you try to link to www.webshop.com/slug/category1/subcategory1, you will get redirected to a 404 - because it obviously doesn't exist.

What I'm interested in, is that i want it to links to the www.webshop.com/slug/ with the categories in the URL open.

I have as i see it 2 problems, 1 big & 1 minor:

  1. I need it to open the /slug/ site but with appended with /category1/subcategory1 - this is the harder of the problems i presume.

  2. I need it to open the categories when.

But how am i supposed to fix these problems? To be honest I have no clue, since i don't know what to search for - so cant gather any information about it.

I was hoping somebody could point me in the right direction, or similar - so i could get this worked out:)

1

Unless there's a reason the subcategory URL has to be www.webshop.com/slug/category1/subcategory1, I would modify this to use a hash instead - i.e. www.webshop.com/slug/category1#subcategory1

This way you won't break WordPress's permalink structure and you can still easily use the hash with JavaScript so render the correct content on the page.

  • Can you use multiple #? so i have #category1#subcategory1? – Mac Mar 30 '17 at 8:37
  • You can only have one hash but you could chain them with a different delimiter (which you might have to urlencode) – Jonny Perl Mar 30 '17 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.