WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Simple navbar/menu with categories and their posts below (14 posts)

  1. Scorpiono
    Member
    Posted 3 years ago #

    Hello everybody, I've seen it's a friendly and helpful community so I decided to join in and ask my first development related question.

    I want to create a navbar in header.php where I have all the categories listed, and as a dropdown (I'll use jQuery or something similar) I will have the post titles from that category.

    Example:
    Category1 Category2 Category3
    Post1_1 Post2_1 Post3_1
    Post1_2 Post2_2 Post3_2
    Post1_3 Post2_3 Post3_3

    The reason is making it as flexible as possible for new categories to be added and their posts listed below. I'm not going to have more than 5 posts per category so there are no other issues rather than how do I display category>all posts as a menu dropdown.

  2. govpatel
    Member
    Posted 3 years ago #

    if you using wordpress 3.0.1 the menu feature let you do that to see the category on the menu page in admin click on Screen Options on right hand top corner and select what want to see on the page than you can add what ever you want in menu.

  3. Scorpiono
    Member
    Posted 3 years ago #

    Not really what I was looking for because I want this on my frong page, for my viewers to see.

  4. govpatel
    Member
    Posted 3 years ago #

    Yes it can be done I just added a blank category page and than add categorys from with in menu and made them all child of category page

    check it out here http://gbpcentral.com

    if you want the posts in each category than just drag the post as child in respective category

  5. Scorpiono
    Member
    Posted 3 years ago #

    Ahhh.. gotcha, I managed to add some categories but not I have no idea how to add the posts as a submenu for the navbar, just as you have when you hover the menu. Any tips? Ty so much for the help so far.

  6. govpatel
    Member
    Posted 3 years ago #

    same way when you click on screen options there is display posts you will see all posts select posts and add them in menu and just drag them in category's move slightly to right for child and if you want add as grandchild like I have than drag under child slightly to right of child.

    post your url so that I can see and guide you better

  7. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    here is some possible code, output in unordered list (2 level deep):

    <?php
    $cats = get_categories();
    echo '<ul class="cat-list">';
      foreach($cats as $cat) :
        $cat_name=$cat->slug;
        echo '	<li class="cat-name">' . $cat->name . '<ul class="cat-posts">';
        $cat_posts = get_posts('numberposts=-1&category_name='.$cat_name);
          foreach($cat_posts as $post) :
            setup_postdata($post);
            echo '<li class="post-link"><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
          endforeach;
        echo '</ul></li>';
      endforeach;
    echo '</ul>';
    ?>
  8. govpatel
    Member
    Posted 3 years ago #

    @alchymyth I have done it without adding any code using menu feature.

  9. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    @govpatel

    is your method dynamic; i.e. will it automatically add new posts and/or new categories?

  10. govpatel
    Member
    Posted 3 years ago #

    No this is done in menu and can be added once the post is added as the post and category will be there.

    where do we put this code in function.php or some where else.

  11. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    my suggested code would be added instead of the menu code.

    obviously, it could be made into a function.

    detailed formatting is up to @Scorpiono, as there are no details of the intended jQuery.

  12. Scorpiono
    Member
    Posted 3 years ago #

    Any jQuery that creates a dropdown fade menu.

    Wow, thanks a bunch both of you guys - you really are great!
    I'll check out a way to integrate alchymyth's code with a dropdown jQuery - if you have a ready example for jQuery too, I owe you a beer mate!

  13. Scorpiono
    Member
    Posted 3 years ago #

    I thank you govpatel, it might work just as you mentioned.
    Alchymyth's one is dynamic and it's exactly what I was looking for.

    I thank you both very much, all I have to do now is figure out the jQuery thingy.

  14. govpatel
    Member
    Posted 3 years ago #

    does that mean that if I change the menu code I will not be able to use the menu feature from within admin

Topic Closed

This topic has been closed to new replies.

About this Topic