• Hi Everybody, how I can display the number of posts in the mega menu items (categories)?

    For example :

    category 1 (2)

    category 2 (10)

    …..

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi argamassa,

    There’s nothing built in to let you do this, so you’d need to use custom code. It looks like this code might work:

    https://wordpress.stackexchange.com/questions/229767/show-posts-count-for-categories-and-tags-in-wp-nav-menu

    Note you need to change the action name from

    walker_nav_menu_start_el

    to

    megamenu_walker_nav_menu_start_el

    Please note, as it’s custom code, it’s not something we cover through support, but hopefully this points you in the right direction. There are more options on google if you search for “wordpress show category count in menu items”.

    Regards,
    Tom

    Thread Starter mi_coleccion_de_sellos

    (@argamassa)

    Thanks for your answer, please can you tell me where can I found the php file for apply the changes you say about the code?

    Regards

    Thread Starter mi_coleccion_de_sellos

    (@argamassa)

    I have added this code to megamenu-pro.php :

    function ggstyle_menu_item_count( $output, $item, $depth, $args ) {
    // Check if the item is a Category or Custom Taxonomy
    if( $item->type == 'taxonomy' ) {
    $object = get_term($item->object_id, $item->object);

    // Check count, if more than 0 display count
    if($object->count > 0)
    $output .= "<span class='menu-item-count'>".$object->count."</span>";
    }

    return $output;
    }
    add_action( 'megamenu_walker_nav_menu_start_el', 'ggstyle_menu_item_count', 10, 4 );

    It’s not working for me.

    Plugin Author megamenu

    (@megamenu)

    You would usually add the code to your themes functions.php file, but as I said previously, I’m afraid this level of custom development isn’t something we cover through support.

    Regards,
    Tom

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

The topic ‘Display post count in menu items’ is closed to new replies.