WordPress.org

Ready to get started?Download WordPress

Forums

Generate navigation list from posts and pages (8 posts)

  1. anandg
    Member
    Posted 7 years ago #

    I want to show a vertical navigation bar on every page that looks something like this:

    * Home
    * Company
    - History
    - About
    * Articles
    - article 1
    - article 2
    - article 3
    * Photos
    * Reports
    - report 1
    - report 2
    - etc.
    * Register
    * Contact

    Some of the sections are posts and some of them are pages. How can I generate a list (ul and li) in a specific order (first Home then Company, etc.) from the posts and pages?

  2. moshu
    Member
    Posted 7 years ago #

    Unless we know exactly which is a Page and which are categories for posts... it's difficult to guess.

    What are those "article 1" etc. Individual posts?

  3. anandg
    Member
    Posted 7 years ago #

    Ah ok, I will mention which are posts and pages:

    * Home (page)
    * Company
    - History (page)
    - About (page)
    * Articles
    - article 1 (post)
    - article 2 (post)
    - article 3 (post)
    * Photos (image gallery)
    * Reports
    - report 1 (page)
    - report 2(page)
    - etc.
    * Register (page)
    * Contact (page)

  4. moshu
    Member
    Posted 7 years ago #

    Automatically you cannot do that. Only manually...
    (part of it maybe doable by some template tags, but not the whole, no way)

  5. anandg
    Member
    Posted 7 years ago #

    Ah, that's too bad.

    And what if I use only posts and no pages. Would it be possible then?

  6. moshu
    Member
    Posted 7 years ago #

    No, it's even more complicated.
    Pages normally are listed in the sidebar menu. Posts are not.

    I know with 3 posts it seems a "wise" idea... but when you will have 365 posts after a year - maybe your visitors will hate you for that: displaying 365 articles in the sidebar and making them to wait a lot of time. Just my $0.02

  7. anandg
    Member
    Posted 7 years ago #

    But you can also limit the number of posts you show in the sidebar. I also know that the number of posts will be very limited.

    I can get a list of all the categories, but if I use all posts, then I find it difficult to show the posts (limited number of posts, say 4 maximum) under the category it belongs.

    I have tried it with a custom query. As a result I get an array. But I can't seem to print it out like I want to.

  8. anandg
    Member
    Posted 7 years ago #

    I've turned all the pages into posts and now I'm manually retrieving the names of the categories and their posts. For example:

    <?php
    $cat9 = $wpdb->get_row("SELECT cat_name FROM $wpdb->categories WHERE cat_id = 9");
    $posts = get_posts( "category=9&numberposts=4" ); ?>
    <?php if( $posts ) : ?>

  9. <?php echo $cat9->cat_name; ?>

    <?php endif; ?>

    The result is a list, which I'm turning with CSS into a CSS dropdown menu from A List Apart.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags