Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $categories = get_categories( array(
- 'orderby' => 'name',
- 'taxonomy' => 'italy',
- 'parent' => 0
- ) );
- $url = site_url().'/italy/'; //Slug da custom taxonomy
- $select = "<select name='cat' id='cat' class='postform'>n"; //Definir o ID que será utilizado no JS
- $select.= "<option value='-1'>Select City</option>n"; //Primeiro item do select
- foreach($categories as $category){
- if($category->count > 0){
- $select.= "<option value='".$url.$category->slug."'>".$category->name."</option>";
- }
- }
- $select.= "</select>";
- echo $select;
- ?>
- <script type="text/javascript"><!--
- var dropdown = document.getElementById("cat");
- function onCatChange() {
- if ( dropdown.options[dropdown.selectedIndex].value != -1 ) {
- location.href = dropdown.options[dropdown.selectedIndex].value+"/";
- }
- }
- dropdown.onchange = onCatChange;
- </script>
Advertisement
Add Comment
Please, Sign In to add comment