• Here’s a sweet little dropdown menu that honors your subcategories and shows the reader what catergory they currently in. I’m sure there is a prettier way to do this but it works!
    Paste this into index.php where you want the menu:
    <form action= “<?php echo $PHP_SELF ?>” method=”get”>Current Category Selected:
    <select name=’cat’ class=’postform’>
    <option value=’0′><?php wp_title(); ?></option>
    <?php wp_dropdown_cats(); ?>
    </select>
    <input type=”submit” name=”submit” value=”view” />
    </form>
    Then paste this near the top of index.php (above “<head profile=”http://gmpg.org/xfn/1″>&#8221;):
    <?php function wp_dropdown_cats($currentcat, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) {
    global $wpdb, $tablecategories, $tablepost2cat, $bgcolor;
    if (!$categories) {
    $categories = $wpdb->get_results(“SELECT * FROM $tablecategories ORDER BY cat_name”);
    }
    if ($categories) {
    foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) {
    $count = $wpdb->get_var(“SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID”);
    $pad = str_repeat(‘– ‘, $level);
    echo “\n\t<option value=’$category->cat_ID'”;
    if ($currentparent == $category->cat_ID)
    echo ” selected=’selected'”;
    echo “>$pad$category->cat_name</option>”;
    wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level + 1, $categories);
    } }
    } else {
    return false;
    }
    }
    ?>
    Enjoy!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Nice piece of work. Thanks for sharing. 🙂 If I wasn’t concerned about getting Google to catalog my deep category links, I’d be using it. 🙂

    Sweet. This is exactly what I wanted to do. Thanks for posting the code.

    Actually, there’s a problem with the code, and maybe you or somebody can help me fix it. Check out http://www.publichealthcenter.com
    Find one of the articles on the main page where I used a MORE tag in the post. Click on (more. ..) You’ll see that the title of the article appears in the combo box on the archives page, but it’s too long, and the box stretches. How can I keep the box from stretching to overlap the article?

    Ok I just changed this:
    <?php wp_title(); ?>
    From the part you insert in the menu code to say:
    All Topics
    Kudos!

    How could I change this to list all categories except for cat 29 and all subcategories of 29?

    See this plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Categories Dropdown Menu’ is closed to new replies.