• Resolved Scorpiono

    (@scorpiono)


    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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • 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.

    Thread Starter Scorpiono

    (@scorpiono)

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

    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 https://gbpcentral.com

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

    Thread Starter Scorpiono

    (@scorpiono)

    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.

    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

    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>';
    ?>

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

    @govpatel

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

    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.

    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.

    Thread Starter Scorpiono

    (@scorpiono)

    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!

    Thread Starter Scorpiono

    (@scorpiono)

    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.

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Simple navbar/menu with categories and their posts below’ is closed to new replies.