Showing Custom Content in a Nav Dropdown

I have a custom content type “balloons”, and I’ve assigned a parent category to a “balloon” item, “Water Balloon”

I’ve made the Balloon category a primary menu item. I want a link to “Water Balloon” to show in the dropdown, as it would if it was a page.

Read More

I don’t know how to do this, or if it’s possible. Any ideas?
Thanks in advance.

Related posts

Leave a Reply

2 comments

  1. If i understand the question correct then you need this:

    add_filter('walker_nav_menu_start_el','auto_category_subMenu',10,4);
    function auto_category_subMenu($item_output, $item, $depth, $args){
        //first you check if the current item is a category
        if (!$item->object == 'category'){
            return $item_output;
        }else{
        //if it is a category then check that it is the right one.
            if ($item->title == 'Water Balloon'){
                   //if we got this far the we are on the parent menu item and
                   // we are going to get all of the balloon post type listed under it
                global $post;
                $tmp_post = $post;
                $args = array(
                    'post_type' => 'balloons',
                    'posts_per_page' => -1,
                    'category_name' => $item->title
                );
                $re = '';
                $submenu_items = get_posts( $args );
                foreach( $submenu_items as $post ){
                    setup_postdata($post);
                    $re .= '<li ><a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a></li>';
                }
                $post = $tmp_post;
                return $item_output.'<ul>'.$re.'</ul>';
            }
        }
        return $item_output;
    }
    

    this code assumes that your category name is “Water Balloon” and your post type is named “balloons” if not simply change that.

  2. It’s very likely you have some kind of collusion somewhere. Is it possible you have something like?

    register_post_type( 'balloon', $args ); and also register_taxonomy( 'balloon', array('balloon'), $args );

    Take a look at the code below. It’s a complete plugin. Compare this with your code.

    <?php
    /*
      @Plugin Name: Balloons - Balloons Directory
      @Plugin URI: http://azizur-rahman.co.uk/
      @Description: Balloons Directory Manager
      @Author: Azizur Rahman
      @Version: 1.0
      @Author URI: http://azizur-rahman.co.uk/
      @package balloons
     */
    
    add_action( 'init', 'azizur_register_cpt_balloons' );
    
    function azizur_register_cpt_balloons() {
    
        $labels = array( 
            'name' => _x( 'balloons', 'balloons' ),
            'singular_name' => _x( 'balloon', 'balloons' ),
            'add_new' => _x( 'Add New', 'balloons' ),
            'add_new_item' => _x( 'Add New balloon', 'balloons' ),
            'edit_item' => _x( 'Edit balloon', 'balloons' ),
            'new_item' => _x( 'New balloon', 'balloons' ),
            'view_item' => _x( 'View balloon', 'balloons' ),
            'search_items' => _x( 'Search balloons', 'balloons' ),
            'not_found' => _x( 'No balloons found', 'balloons' ),
            'not_found_in_trash' => _x( 'No balloons found in Trash', 'balloons' ),
            'parent_item_colon' => _x( 'Parent balloon:', 'balloons' ),
            'menu_name' => _x( 'balloons', 'balloons' ),
        );
    
        $args = array( 
            'labels' => $labels,
            'hierarchical' => false,
            'description' => 'balloons content type',
            'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
    //        'taxonomies' => array( 'page-category', 'balloon-category' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
    
    
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post'
        );
    
        register_post_type( 'balloons', $args );
    }
    
    
    add_action( 'init', 'azizur_register_taxonomy_balloon_types' );
    
    function azizur_register_taxonomy_balloon_types() {
    
        $labels = array( 
            'name' => _x( 'Balloon Types', 'balloon types' ),
            'singular_name' => _x( 'Balloon Type', 'balloon types' ),
            'search_items' => _x( 'Search Balloon Type', 'balloon types' ),
            'popular_items' => _x( 'Popular Balloon Type', 'balloon types' ),
            'all_items' => _x( 'All Balloon Type', 'balloon types' ),
            'parent_item' => _x( 'Parent Balloon Types', 'balloon types' ),
            'parent_item_colon' => _x( 'Parent Balloon Types:', 'balloon types' ),
            'edit_item' => _x( 'Edit Balloon Types', 'balloon types' ),
            'update_item' => _x( 'Update Balloon Types', 'balloon types' ),
            'add_new_item' => _x( 'Add New Balloon Types', 'balloon types' ),
            'new_item_name' => _x( 'New Balloon Types Name', 'balloon types' ),
            'separate_items_with_commas' => _x( 'Separate balloon type with commas', 'balloon types' ),
            'add_or_remove_items' => _x( 'Add or remove balloon type', 'balloon types' ),
            'choose_from_most_used' => _x( 'Choose from the most used balloon type', 'balloon types' ),
            'menu_name' => _x( 'Balloon Types', 'balloon types' ),
        );
    
        $args = array( 
            'labels' => $labels,
            'public' => true,
            'show_in_nav_menus' => true,
            'show_ui' => true,
            'show_tagcloud' => true,
            'hierarchical' => true,
    
            'rewrite' => true,
            'query_var' => true
        );
    
        register_taxonomy( 'balloon_types', array('balloons'), $args );
    }
    
    function azizur_balloons_cpt_rewrite_flush() {
      flush_rewrite_rules();
    }
    register_activation_hook(__FILE__, 'azizur_balloons_cpt_rewrite_flush');
    register_deactivation_hook(__FILE__, 'azizur_balloons_cpt_rewrite_flush');
    
    ?>