If a 'category' is added to the menu using the 'menus' tool in WordpressWordPress, I want my theme to automatically add a submenu containing links to all of the posts in that category.
In my functions.phpfunctions.php
file I have created a function and hooked it to 'walker_nav_menu_start_el'walker_nav_menu_start_el
action. By passing the $item$item
variable into the function I am able to identify if the current menu item is a category and what category it is. But I'm having trouble creating the list of links with post titles for all posts in that category.
At first I thought I could use the 'get_posts'get_posts
function and a foreach loop, but because I'm not outputting, I'm just building an output variable to be passed back to the 'walker_nav_menu_start_el'walker_nav_menu_start_el
action, it's merely outputting the details of the current post instead of the details for each post it loops through. This is the code I tried:
How can I get each category to list its posts in the menu? Can I do it with this action hook? Or should I be looking at a custom walker?
Thanks, Josh