• As you can see in the example below the hierarchy of categories can become quite complex.

    Men
        Tops
            Dress shirt
            Polo shirt
            T-shirt
        Trousers
            Overalls
            Cargo
            Denim
        Shoes
            Trainers
            Sandals
            Smart shoes
            Boots
    Women
        Tops
            Dress shirt
            Polo shirt
            T-shirt
        Trousers
            Overalls
            Cargo
            Denim
        Shoes
            Trainers
            Sandals
            Smart shoes
            Boots
    
    Children
        Tops
            Dress shirt
            Polo shirt
            T-shirt
        Trousers
            Overalls
            Cargo
            Denim
        Shoes
            Trainers
            Sandals
            Smart shoes
            Boots

    At the moment WordPress is designed to have unique slugs so with a three-level hierachy such as

    Mens
        Tops
            Polo shirt

    the URL/slug would result in this for example:-
    http://www.domain.com/category/mens/mens-tops/mens-tops-polo-shirt

    A more ideal friendly URL/slug would be:-
    http://www.domain.com/category/men/tops/polo-shirt

    My knowledge of WordPress is very basic but I am aware of the functions.php file. Is there any functions I can use to change the bahaviour of WordPress so it allows categroies and slugs to have the same name so long as the parent is unique? If not can I make a suggestion for a future build?

    Many thnaks

    Will

    • This topic was modified 7 years, 1 month ago by willowen100.
Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m not sure if you’re referring to the category URL, or individual post’s URL.

    For category URL, your structure:

    Mens
        Tops
            Polo shirt

    Should result in the URL:

    http://www.domain.com/category/mens/tops/polo-shirt

    (which, by the way, doesn’t match any of the URLs you gave above 🙂 )

    This is how WordPress works by default: the parent category’s slug is not added to the child category’s slug as you seem to imply.

    If you’re referring to individual post URL, see Permalink for how you can customize the URLs to your heart’s desire.

    And if you’re referring to some plugin or shopping cart’s URLs, then I’ve no idea and your best bet would be to consult that particular plugin’s vendor.

    Thread Starter willowen100

    (@willowen100)

    Hi George

    Cheers for the reply. I made a typo in the second URL, It was supposed to have a ‘s’ on the end of ‘men’. Anyway that is the URL I am wanting to go for, but the problem I have is if there are other child categories with the same name they’ll have clashing slugs. Thereby correcting it to

    http://www.domain.com/category/mens/mens-tops/mens-tops-polo-shirt

    now makes the URL so much longer. That is why I was hoping there may be a way to append the parent category to the child category so that the hierarchy is used.

    Many thanks

    Will

    Thread Starter willowen100

    (@willowen100)

    Would I be better off using a custom post type plugin and then create as many taxonomies as I want? That way I could have heirachal all my parent categories as custom post types and have the child categories set as taxomonies?

    These are the plugins that I’m thinking of using:-

    https://en-gb.wordpress.org/plugins/custom-post-type-ui
    https://en-gb.wordpress.org/plugins/advanced-custom-fields

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Allow hierarchical slug support for use with categories’ is closed to new replies.