WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Possible to display Categories in the Page hierarchy? (8 posts)

  1. ahhrrr
    Member
    Posted 5 years ago #

    I'm developing a wordpress site as an intranet at my company. Most of the content (static) within the site will be stored in Pages. I have created a post hierarchy (how-tos, forms, etc) and it shows up in the navigation view. Easy.

    But for some of the content, it seems more appropriate to use posts. (i.e. internal company announcements, weekly IT tips, and periodic staff profiles.) Most of these will be embedded on the home/portal page.

    The problem is that I would also like to link to the archives of these posts, by categories. Unfortunately, the only things showing up in my navigation list are pages.

    Is there any way to include post categories in the list of pages? Failing that, is there any way I can use custom page templates so they actually function as category archive pages?

    Thanks for your help! Sorry to clutter the support board.

  2. buddha trance
    Member
    Posted 5 years ago #

    You can add <?php wp_list_categories(); ?>, either to your theme sidebar.php, or into header.php

    I just tried adding it right after <?php wp_list_pages(); ?> in header.php of my test copy, and now the menu is showing both pages and categories, so it works.

  3. ahhrrr
    Member
    Posted 5 years ago #

    Thanks! This is exactly the tip I needed.

  4. djones101
    Member
    Posted 5 years ago #

    Can you change which categories you would like to appear on each page? Say you have 5 pages and you want there to be different categories on each page?

  5. buddha trance
    Member
    Posted 5 years ago #

    @ djones101

    Yes, you can. Read here about creating a variable sidebar with conditional tags
    http://codex.wordpress.org/Conditional_Tags#Variable_Sidebar_Content

    The code would be something similar to

    <?php
    // let's generate info appropriate to the page being displayed
    if (is_home()) {
            // we're on the home page, so let's show a list of all top-level categories
            echo "<ul>";
            wp_list_categories('optionall=0&sort_column=name&list=1&children=0');
            echo "</ul>";
    } elseif (is_page(name of page 1)) {
            // now we start to display categories conditionally, depending on which page we are on
             echo "<ul>";
            wp_list_categories('orderby=name&include=3,5,9,16');
            echo "</ul>";
    } elseif (is_page(name of page 2)) {
    echo "<ul>";
            wp_list_categories('orderby=name&include=4,6,8,12');
            echo "</ul>";
    } elseif (is_page(name of page 3)) {
    echo "<ul>";
            wp_list_categories('orderby=name&include=7,21,64');
            echo "</ul>";
            } else {
                  // catch-all for all other pages, listing all categories
                 echo "<ul>";
            wp_list_categories('optionall=0&sort_column=name&list=1&children=0');
            echo "</ul>";
            }
    ?>
  6. djones101
    Member
    Posted 5 years ago #

    buddha,

    Currently I have this in my header.php file. This controls the nav on my page.

    <ul>
    	<li><a href="#">Home</a></li>
    	<li><a href="#">What is SR22 Insurance?</a></li>
    	<li><a href="#">What is Non-Owner Insurance?</a></li>
    	<li><a href="#">Financial Responsibility Form</a></li>
    	<li><a href="#">Auto Insurance Definitions</a></li>
    	<?php wp_list_bookmarks('title_li=&categorize=0'); ?>
    	<li><a href="#">Contact Us</a></li>
    </ul>

    I would like to be a able to have the bookmarks for the post/page appear between auto insurance definitions and contact us. However, I would only like the bookmarks for that specific post to be in that area.

    As an example, lets say I have 3 posts. Post one is titled fruit, post 2 is titled veggies, post 3 is titled pets. I have also created a category for each title. I then created 20 links and assigned them in the dashboard to those categories.

    I would like to have those links appear between auto insurance definitions and contact us in my nav. Is there a way to do this without having to assign the ID of each link to the statement in the hardcode? Can I just assign the link category id to the page?

    The reason I ask... I am creating a site that will include all 50 states and then potentially 30-40 links per state. I would like an easy way to assign those links.

    Thanks

    Dan

  7. buddha trance
    Member
    Posted 5 years ago #

    djones,

    I haven't tried using conditional bookmarks, will look into it...

    See if, as a start, these references may help you
    http://justintadlock.com/archives/2009/01/06/easy-navigation-menus-in-wordpress on using bookmarks for navigation

    and http://codex.wordpress.org/Template_Tags/wp_list_bookmarks

    on this page http://wphacks.com/wordpress-blogroll-code-separating-your-categories/ there is the following code mentioned

    <?php wp_list_bookmarks('categorize=1&before=<li>&title_before=<h2>&title_after=</h2>&category_before=</n>&category_before=</n>&after=</li>&orderby=url'); ?>

    He is using categorize=1 (true). I don't know if this makes it conditional, worth a try.

    Hope this helps...

  8. djones101
    Member
    Posted 5 years ago #

    Nope,

    It didn't work. It just seems a little weird that they have link categories and no way to dynamically input them into the page.

Topic Closed

This topic has been closed to new replies.

About this Topic