Forums

Hide some categories from top nav menus (6 posts)

  1. dotman
    Member
    Posted 4 years ago #

    I'm using the Exclude Pages From Navigation plugin to hide certain pages from the top drop down menu.

    Is there a plugin or a way I can do the same with Categories?

  2. Shane G
    Member
    Posted 4 years ago #

    Hi,

    You can fulfill your requirement with with category tags. You need to use wp_list_categories tag with exclude option. Here is an example:

      <?php
      wp_list_categories('orderby=name&include=7,13'); ?>

    This will exclude category 7 and 13.

  3. FunkyMagicUK
    Member
    Posted 4 years ago #

    Try this...

    Find the id of the categories you want to exclude (I'm sure there's an easy way to do this but I'm just returning to WP after a long time away!) - I browse the wp_terms table in the database, and note the ids of the categories you want to exclude.

    THEN...

    In the admin interface, go to edit 'header.php', search for wp_list_categories, and then just append "&exclude=x,y,z".

    For example, in the template I'm using, my line in header.php looked like..

    ?php wp_list_categories('sort_column=name&title_li=&depth=2'); ?>

    If I edit it so it looks like

    ?php wp_list_categories('sort_column=name&title_li=&depth=2&exclude=1,12'); ?>

    Then it does exactly what I want.

  4. FunkyMagicUK
    Member
    Posted 4 years ago #

    Quick way of getting id's is to hover over them in the admin and look at the cat id in the URL shortcut.

  5. thesoundchurch
    Member
    Posted 3 years ago #

    hey, i tried this and it worked. problem is now i'm seeing the words "no categories" in my nav bar. is there a way to get rid of that?

  6. kcordas
    Member
    Posted 3 years ago #

    Here is how...just put this on the top of your template...

    <?php
    function bm_dont_display_it($content) {
      if (!empty($content)) {
        $content = str_ireplace('<li>' .__( "No categories" ). '</li>', "", $content);
      }
      return $content;
    }
    add_filter('wp_list_categories','bm_dont_display_it');
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic