• Resolved RaiderKat

    (@raiderkat)


    Hi, I was wondering if anyone knows if there is a way to create a menu item in the main menu that would have a dropdown list of authors?

    I’m trying to add a menu item that would automatically update new contributors as we add them?

    I’ve been looking everywhere and cant seem to figure out a way to do it.

    Thanks so much!

Viewing 15 replies - 31 through 45 (of 45 total)
  • Thread Starter RaiderKat

    (@raiderkat)

    GOT IT! YAY! Thanks so much for your help! I really appreciate it! Here is the code I used. Only thing I cannot get to work is excluding the admin, but that isnt a huge deal. Thanks so much!!

    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;
    }

    Isn’t that the same code I posted in my seventh post? Well besides the &exclude_admin=0 part any how. Also is it live on the site because I don’t see it right now.

    And by defualt “exclude_admin” is set to 1 which is true meaning it excludes the admin. You are setting it to 0 with make the statement false so it will not exclude the admin.

    Thread Starter RaiderKat

    (@raiderkat)

    ya no i tried not putting it, i tried setting it to 1, i tried setting it to 0, nothing worked..the admin is still showing up..really strange
    Just happens i posted the one where i set to 0 lol

    Thread Starter RaiderKat

    (@raiderkat)

    It is not on the site. I actually was just testing it on my personal site. I needed the code for a client and couldnt get it to work. They actually only have one menu so it probably would have been fine but i didnt want it to break if they added another menu down the line. I really appreciate all of your help!

    Thread Starter RaiderKat

    (@raiderkat)

    it is almost exactly the code you had except you were missing the = after $items .

    Thread Starter RaiderKat

    (@raiderkat)

    should be $items .=

    Yeah your right, yeah my brain wasn’t working that night… to late.

    It looks like exclude_admin only works if the admin’s login user name is admin. Is the admin’s name admin?

    Thread Starter RaiderKat

    (@raiderkat)

    It is

    Thread Starter RaiderKat

    (@raiderkat)

    I actually changed it to show up as FAV because i couldnt get it to not show up

    Hi guys!

    I’ve been trying to achieve exactly what RaiderKat needs, and so far, no luck!

    I’ve added this code to my functions.php, but no luck.

    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;
    }

    Was this code customized to work only with your example, or is it supposed to work everywhere?

    Thanks!!

    Eric

    Thread Starter RaiderKat

    (@raiderkat)

    Erik it should work for anyone. Only issue i’m having is for some reason its putting an extra

    <li>

    [Moderator note: In future please wrap all code in backticks]

    at the beginning..i’m not sure why. Trying to figure it out now.

    Only thing you need to do is specify the theme location and it should work for you.

    How to find the theme location? Primary gives no result.
    I’ve tried with array('menu' => 'Project Nav' )); also, and no result.
    Thanks for the help!!
    E.

    Of course, you put an extra li, because “Authors” has to be a new list element in the menu, at the same time containing the ul class submenu and the li elements of the different authors (to make the dropdown). All this makes total sense to me. Is on the pure php part that I get lost… And so far no luck

    Hi guys!

    I got it working by adding the !is_admin() and pasting the code into nav.php and not functions.php. Also, I’m using Roots.io starter theme, thats why the extra classes on link and list elements.

    Hope it saves somebody’s ass at some point! : )

    function add_last_nav_item($items, $args) {
      if (!is_admin() && $args->theme_location == 'primary_navigation') {
        $items .= '<li><a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="#">Autoren <b class="caret"></b></a><ul class="dropdown-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;
    }
    add_filter( 'wp_nav_menu_items', 'add_last_nav_item', 10, 2 );
Viewing 15 replies - 31 through 45 (of 45 total)
  • The topic ‘Creating a dropdown in menu that lists authors’ is closed to new replies.