I'm attempting to setup a custom URL structure within posts that makes all parents and sub child's accessible, but all attempts have failed with various errors.
My category structure looks something like this:
- Cars
-- Mondeo
--- 1994
---- Postname
The idea is that people can access the following pages:
example.com/cars/
example.com/cars/mondeo/
example.com/cars/mondeo/1994/
example.com/cars/mondeo/1994/postname/
Postname (the article will be added to all categories listed above and the primary will be set to the last sub catagory listed).
What I've tried:
- Setting permalinks to
/%category%/%postname%/
this results in 404's when attempting to visit/cars/mondeo/
or/cars/mondeo/1994/
. This however works when visiting/cars/
and/cars/mondeo/1994/postname/
. - Using
/%category%/%subcategory%/%postname%/
as the permalinks makes the sub categories work, but then breaks the parents and the postnames... not good.
.htaccess / mod_rewrite is enabled and working:
I have tested the .htaccess adding a deny, i.e:
# Test HTACCESS
Deny from all
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END Word
I hate the .php method, surely there is a better way...
The only solutions I've been able to find on here are by using a dirty .php method, which seems silly, I cant believe that WordPress can't handle this and I imagine that this has been asked in various forms and I've not found them, in which case please kindly point me in the right direction.
.php
method works, it adds a unique element to the pattern that will only match posts. Have a look at this question which is a similar issue, you have to do a bit of work yourself to help WordPress know what you're asking for.