Title: creating sub category navigation
Last modified: August 19, 2016

---

# creating sub category navigation

 *  [daniel4ing](https://wordpress.org/support/users/daniel4ing/)
 * (@daniel4ing)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/creating-sub-category-navigation/)
 * For those people who want subcategories on their single.php pages, this is how
   I solved it. I just wanted to share it since it seems every plugin doesn’t work
   at the moment with the latest version of wordpress. First thing I did was make
   the required categories, ‘fruit’ and ‘vegtables’. You have to do this first since
   wordpress wants the category slugs to be unique but it is okay to name your menus
   after the category slugs later on. So after that I made 3 menus. The ‘main’ menu
   which contain links to the ‘fruit’ and ‘vegtables’ categories. Then made the 
   menus for ‘fruit’ and ‘vegtables’.
 * On the homepage I use the following code as my main navigation:
 * `<?php wp_nav_menu( array('menu' => 'main' )); ?>`
 * For the category page I use:
 *     ```
       <?php
       $cat_object = $wp_query->get_queried_object();
       $parentcat = ($cat_object->category_parent) ? $cat_object->category_parent : $cat;
   
       echo "<ul>";
       wp_list_cats("child_of=$parentcat");
       echo "</ul>";
       ?>
       ```
   
 * And on the single.php website I use:
 *     ```
       <?php
   
       if(strstr($_SERVER['HTTP_REFERER'],'fruit'))
       {
       echo "<ul>";
       wp_nav_menu( array('menu' => 'fruit' ));
       echo "</ul>";
       } 
   
       elseif (strstr($_SERVER['HTTP_REFERER'],'vegtables'))
       {
       echo "<ul>";
       wp_nav_menu( array('menu' => 'vegtables' ));
       echo "</ul>";
       }
   
       else
       {
       echo "<ul>";
       wp_nav_menu( array('menu' => 'main' ));
       echo "</ul>";
       }
       ?>
       ```
   
 * The last thing I did to get it working the way I wanted was change the ‘Permalink
   Settings’ to ‘Custome settings’:
 * `/%category%/%postname%/`
 * The reason I do it this way is because wordpress single.php doesn’t have any 
   options to grab the category information from the page it just came from and 
   didn’t want to create category and single templates because of a navigation. 
   Hope I made some folks happy with it. If you guys have any other tips to get 
   something similar set up then I’d be keen to see your approach.

The topic ‘creating sub category navigation’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [child](https://wordpress.org/support/topic-tag/child/)
 * [menu](https://wordpress.org/support/topic-tag/menu/)
 * [parent](https://wordpress.org/support/topic-tag/parent/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [daniel4ing](https://wordpress.org/support/users/daniel4ing/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/creating-sub-category-navigation/)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
