WordPress.org

Support

Support » How-To and Troubleshooting » Generate navigation list from posts and pages

Generate navigation list from posts and pages

  • 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?

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

    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)

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

    Ah, that’s too bad.

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

    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

    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.

    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 ) : ?>

  • <?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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Generate navigation list from posts and pages’ is closed to new replies.
Skip to toolbar