WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help with wp_list_authors (4 posts)

  1. RaiderKat
    Member
    Posted 7 months ago #

    Hi, I am trying to implement a menu item to list authors. The code i came up with works GREAT..only one issue! I have two nav menus registered, Primary and Secondary.

    When I add the code to my page, targeting the primary menu, the secondary menu disappears. The box is still there but all the links are gone.

    Any ideas why?? here is the code I'm using:

    function wps_nav_authors($items, $args){
    
        if( $args->theme_location == 'primary' )
    
            return $items . '<li><a href="#">Authors</a><ul class="sub-menu"><li>' . wp_list_authors('show_fullname=1&optioncount=0&orderby=post_count&order=DESC&number=8&echo=0') . '</li></ul></li>';
    
    }
    
    add_filter('wp_nav_menu_items','wps_nav_authors', 10, 2);

    Thanks so much for your help!

  2. JumboClicks
    Member
    Posted 7 months ago #

    I would view source on the page
    that should help you figure out whats happening
    If the data is there
    or if its not executing

  3. RaiderKat
    Member
    Posted 7 months ago #

    when i have the code in there all that shows up for the secondary menu is this
    <div class="menu-top_menu-container"><ul id="menu-top_menu" class="menu"></ul></div>

    no list

    The primary menu works fine, and the authors are added to the menu

    If i take the code back out..they both work

  4. RaiderKat
    Member
    Posted 7 months ago #

    For anyone who is looking, I figured I would post the solution! Here is the code that works! Happy Coding!

    add_filter( 'wp_nav_menu_items', 'wps_nav_authors', 10, 2 );
    function wps_nav_authors ( $items, $args ) {
        if ( $args->theme_location == 'primary') {
            $items .= '<li><a href="#">Authors</a><ul class="sub-menu"><li>' . wp_list_authors('show_fullname=1&optioncount=0&exclude_admin=0&orderby=post_count&order=DESC&number=8&echo=0') . '</li></ul></li>';
        }
        return $items;
    }

Reply

You must log in to post.

About this Topic