Getting list of categories as a dropdown menu

Description

This code generates dropdown menu with categories. Change ‘child_of’  => 4 to the category of your choice

This code generates dropdown menu with categories. Change ‘child_of’  => 4 to the category of your choice

CSS Source Code

                        
                          #categories {
    list-style: none;
    border: none;
    display: table;
    margin-left: auto;
    margin-right: auto;
}

#categories select {
    float: left;
    width: 400px;
    margin-right: 5px;
    height: 42px;
}                        
                        

PHP Source Code

                        
                          <div id="categories">
<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
						
						<?php $args = array(
							'show_option_all'    => '',
							'show_option_none'   => '',
							'option_none_value'  => '-1',
							'orderby'            => 'ID',
							'order'              => 'ASC',
							'show_count'         => 0,
							'hide_empty'         => 1,
							'child_of'           => 4,
							'exclude'            => '',
							'include'            => '',
							'echo'               => 1,
							'selected'           => 0,
							'hierarchical'       => 0,
							'name'               => 'cat',
							'id'                 => '',
							'class'              => 'postform',
							'depth'              => 0,
							'tab_index'          => 0,
							'taxonomy'          =>'category',
							'hide_if_empty'      => false,
							'value_field'	     => 'term_id',
						); ?>
						
<?php wp_dropdown_categories( $args ); ?>
<input type="submit" name="submit" value="view" />
</form>
</div>                        
                        


Post Categories