• Resolved mhuynh55

    (@mhuynh55)


    I am currently implementing an archive index by an author and was seeing if someone here could assist me as I do not know PHP in-depth.

    The following php displays a list of categories as a drop-down menu:

    <?php wp_dropdown_categories('orderby=name&show_count=1&show_option_none=Select Category'); ?>
    <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>

    I was hoping that rather than for the drop-down menu to show all the categories I have created through my WP Dashboard, I could only show specific categories only. For example, could I specify only the drop-down menu to show cat=16 or 9?

Viewing 1 replies (of 1 total)
  • Thread Starter mhuynh55

    (@mhuynh55)

    If anyone else requires future reference, the solution was just to amend the code and add &exclude=10 to:

    <?php wp_dropdown_categories('orderby=name&show_count=1<strong>&exclude=10</strong>&show_option_none=Select Category'); ?>
    <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>
Viewing 1 replies (of 1 total)
  • The topic ‘Using WP Dropdown Categories’ is closed to new replies.