WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Creating a dropdown in menu that lists authors (46 posts)

  1. RaiderKat
    Member
    Posted 7 months ago #

    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!

  2. Pyrate.Ned
    Member
    Posted 7 months ago #

  3. RaiderKat
    Member
    Posted 7 months ago #

    Thanks for the response. I think that is kind of what i'm looking for but i want to add the dropdown list to the main navigation menu so it would be like this: (you click on contributor and the drop down menu appears)
    Home Contributors About Contact
    drop down menu

    I'm not sure how to add that functionality as the WordPress "Menus" only gives posts, pages and categories??

    Thanks again!

  4. Pyrate.Ned
    Member
    Posted 7 months ago #

    It is possible but you would need to know some javascript, html and css.
    There are many ways to do this as in any type of coding project but what I would do is use the javascirpt to stop the anchor of contributors from leaving the page then have it fade in or make the the dropdown menu appear instantly. In the template you would add wp_get_author(array('name' => 'author')); in the same div or element that holds the nav. In the css you would have to make the div or element that holds the nav position relative, then make the dropdown position absolute and position it to be under the contributors link with top and left or right and display:none.

  5. RaiderKat
    Member
    Posted 7 months ago #

    The HTML and the CSS I can handle, not sure if i can figure out the javascript code. Havent used javascript in forever! But thank you that was very helpful! I'll see if I can figure out the javascript code to use!

    Thanks so much for your help!

  6. RaiderKat
    Member
    Posted 7 months ago #

    So i found a few other things and played around with them, 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);

    it actually seems to be working great except..for some reason, it makes my second menu disappear.

    I have two menus on my page, one at the top named top_menu and the main navigate(where i want to put the authors named main_menu. Any idea why it would make my top menu disappear? The container is still there, but the links have disappeared.

    Thanks so much for your help. You definitely put me in the right direction!

  7. Pyrate.Ned
    Member
    Posted 7 months ago #

    post a link to your site/page.

  8. RaiderKat
    Member
    Posted 7 months ago #

    http://www.fansagainstviolence.org/

    If you look up at the top there should be a menu with the Home, about and contact buttons..but they disappear when i put that code in

  9. Pyrate.Ned
    Member
    Posted 7 months ago #

    remove the code really fast and let me see the secondary nav

  10. RaiderKat
    Member
    Posted 7 months ago #

    Done

  11. Pyrate.Ned
    Member
    Posted 7 months ago #

    ok put it back

  12. RaiderKat
    Member
    Posted 7 months ago #

    k done

  13. Pyrate.Ned
    Member
    Posted 7 months ago #

    Try this

    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);
  14. RaiderKat
    Member
    Posted 7 months ago #

    No..still not working..so odd! Should only effect the Primary menu..

  15. Pyrate.Ned
    Member
    Posted 7 months ago #

    Ok one more

    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&orderby=post_count&order=DESC&number=8&echo=0') . '</li></ul></li>';
        }
        return $items;
    }
  16. RaiderKat
    Member
    Posted 7 months ago #

    Parse error: syntax error, unexpected '}' in /home2/ksamoun/public_html/wp-content/themes/twentyeleven/functions.php on line 2920

  17. Pyrate.Ned
    Member
    Posted 7 months ago #

    yeah sorry missed a ; retry the code above

  18. RaiderKat
    Member
    Posted 7 months ago #

    No..i think there has to be the add filters on there

  19. Pyrate.Ned
    Member
    Posted 7 months ago #

    its there on the top of the code

  20. Pyrate.Ned
    Member
    Posted 7 months ago #

    right now is the code out or is it my code?

  21. RaiderKat
    Member
    Posted 7 months ago #

    the menus are working but the Authors arent showing up

  22. Pyrate.Ned
    Member
    Posted 7 months ago #

    Try this

    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&orderby=post_count&order=DESC&number=8&echo=0') . '</li></ul></li>';
    return $items;
        }
    }
    add_filter('wp_nav_menu_items','wps_nav_authors', 10, 2);

    sorry damn backticks

  23. RaiderKat
    Member
    Posted 7 months ago #

    now the top menu isnt showing and the Authors arent showing

  24. Pyrate.Ned
    Member
    Posted 7 months ago #

    haha sorry grap the code the the filter at the bottom

  25. RaiderKat
    Member
    Posted 7 months ago #

    lol which one?

  26. RaiderKat
    Member
    Posted 7 months ago #

    Same..no author no top nav

  27. Pyrate.Ned
    Member
    Posted 7 months ago #

    the one with the sorry damn backticks, I move the add_filter to after you declare the function

  28. RaiderKat
    Member
    Posted 7 months ago #

    ya thats the one i have on there now..still no top nav or authors

  29. RaiderKat
    Member
    Posted 7 months ago #

    maybe it needs to be in an if statement? if theme_location == 'primary' else if 'secondary?

  30. Pyrate.Ned
    Member
    Posted 7 months ago #

    Sorry will have to continue tomorrow or Monday, not sure my brain is working right at this point =) Way to late for me. I will have to look at it with a fresh head

Reply »

You must log in to post.

About this Topic