• Hi everyone,

    I’d like to build a “traditional” menu structure from categories in a clean and lean way, that separates the main menu (main categories) from the submenus (subcats).

    I know that using
    <?php wp_list_cats(‘children=0’); ?>,
    I can just display the main cats.

    And I know that using
    <?php wp_list_cats(‘child_of=1’); ?>,
    I can just display the subcats of main cat 1.

    BUT what I’d like to do is passing the parameter of the actual main category to the wp_list_cats that is supposed to display the subcategories (therefore, I could keep just one template).

    So: is there a way to pass “the_category_ID” to wp_list_cats?

    Any help is appreciated.

    Kind regards

    Dr. Jo

    PS: All the best for 2005 … !

Viewing 4 replies - 1 through 4 (of 4 total)
  • Can you clarify what you mean by “the actual main category?”

    If you are attempting to pass the ID of a category page you are actually on, try this:

    <?php wp_list_cats("child_of=$cat"); ?>

    If this is not what you’re looking for, please explain in more detail what you’re trying to accomplish.

    Thread Starter drjo

    (@drjo)

    Great job! (with that name … it had to be good ;-))

    That was exactly what I was looking for …

    Thanks a lot!

    It’s GREAT!!
    This was also what I was looking for
    Thanks!!!

    I’ve found a solution for small sites that need this.

    In each page in your menu structure add a ‘custom field’ (at the bottom of the manage post page in the admin area).

    Find out the ID of the main section page. For instance my About page has an ID of 2 – this appears to the left of the page name on the Manage Pages page.

    Add a custom field with the name ‘section’ and the value 2 to each page within that section of your site.

    Then, to make your menu, edit your header.php page and paste in the following code.

    <?php
    if($section_id = get_post_meta($page_id, ‘section’, $single = true))
    {
    wp_list_pages(‘depth=1&sort_column=menu_order&title_li=&child_of=’.$section_id );
    }
    ?>

    Instant submenu that does not disappear when you click on one of the pages in the section.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘(How) can I pass “the_category_ID” to “wp_list_cats()”?’ is closed to new replies.