Forums

[resolved] Removing categories from JS dropdown menu (3 posts)

  1. jonblazn
    Member
    Posted 3 years ago #

    I'm using the code listed below in my header for a dropdown menu of categories. Can someone please explain to me how I would exclude categories. I tried 2 methods but they didn't seem to work. Thanks in advance!

    <div class="sdl">
    	<?php wp_dropdown_categories('show_option_none=Product Categories'); ?>
    
    <script type="text/javascript"><!--
        var dropdown = document.getElementById("cat");
        function onCatChange() {
    		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    			location.href = "<?php echo get_option('home');
    ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    		}
        }
        dropdown.onchange = onCatChange;
    --></script>
      </div>
  2. Otto
    Tech Ninja
    Posted 3 years ago #

    Use the exclude parameter, and give it a list of category numbers to exclude.

    wp_dropdown_categories('show_option_none=Product Categories&exclude=1,2,3');

  3. jonblazn
    Member
    Posted 3 years ago #

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic