Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #458006

    Hello,
    I would like to add “count” of posts under sub categories (in parenthesis) to a nested sidebar menu like;
    -Category
    – Sub Category A (5)
    – Sub Category B (3)

    I had found a code by your moderator (“DUDE”) to modify nested sidebar menu and added into my functions.php ;
    (I’m not sure if it’s necessary)

    add_filter('avf_sidebar_menu_filter', 'avia_add_parent_page_to_sidebar', 10, 3);
    function avia_add_parent_page_to_sidebar($sidebar_menu, $args, $post)
    {
        $parent = $post->ID;
    
        if(!empty($post->post_parent))
        {
            if(isset($post->ancestors)) $ancestors  = $post->ancestors;
            if(!isset($ancestors)) $ancestors  = get_post_ancestors($post->ID);
            $root		= count($ancestors)-1;
            $parent 	= $ancestors[$root];
        }
    
        $current = ($post->ID == $parent) ? "current_page_item" : "";
    
        $parent_page = '<li class="page_item page-item-'.$parent.' ancestor_page_item '.$current.'">';
        $parent_page .= '<a href="'.get_permalink($parent).'">'.get_the_title($parent).'</a>';
        $parent_page .= '</li>';
    
        $sidebar_menu = str_replace("<ul class='nested_nav'>", "<ul class='nested_nav'>{$parent_page}", $sidebar_menu);
    
        return $sidebar_menu;
    }

    Thank you

    #458612

    It would be much more useful as custom widget I guess for other users as well, looking for a solution from moderators and developers.
    Thank you,
    Best Regards.

    #458644

    Please someone answer

    #458756

    Still no answer?

    #459790

    Hi,

    Can you post the link to your website? there’s a native WP function that let you do this:
    https://codex.wordpress.org/Function_Reference/wp_count_terms

    Regards,
    Josue

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.