Guest User

The Event Calendar Category Dropdown

a guest
Jun 20th, 2012
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             <?php
  2.            $categories = get_categories(
  3.                array(
  4.                   'taxonomy'      => TribeEvents::TAXONOMY,
  5.                    'selected'      => 0,
  6.                    'orderby'       => 'name'
  7.                 ) );
  8.             ?>
  9.  
  10.             <script type="text/javascript"><!--
  11.            function onCatChange(select) {
  12.                var slug = select.options[select.selectedIndex].value;
  13.                var link = '<?= tribe_get_events_link() ?>';
  14.                location.href = (slug == 'all') ? link : link + 'category/' + slug;
  15.            }
  16.            --></script>
  17.  
  18.             <select id="categories" onchange="onCatChange(this)" >
  19.                 <option value="all">All Events</option>
  20.                 <?php
  21.                foreach ($categories as $cat) {
  22.                    if (tribe_meta_event_category_name() == $cat->name) $selected='selected';
  23.                     else $selected = '';
  24.                 ?>
  25.                 <option value="<?= $cat->slug ?>" <?= $selected ?>><?= $cat->name ?></option>
  26.                 <?php } ?>
  27.             </select>
Advertisement
Add Comment
Please, Sign In to add comment