WordPress menu from categories, subcategories and posts

Recently we needed to create a custom menu of posts in a hierarchy using the following format:

- category
-- posts
-- subcategory
--- posts
- category
-- subcategory
--- posts

Note that if a category doesn't have subcategories, the posts are listed in the same level as subcategories.

I discussed the issue with @nielslange and he approached it in the following fashion:

https://gist.github.com/nielslange/34378937127c476a6c5614c94415e534

I've then modified his code for use in a WordPress menu structure:

https://gist.github.com/FreshLondon/4f453217aca5c53ba2605640b41dc2c5

This results in the following:

Desktop

Mobile

I'll add the CSS soon!

Filed under: 
© 2021 - FreshLondon