Guest User

The Event Calendar Category Dropdown

a guest
Jun 20th, 2012
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.18 KB | None | 0 0
  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 :
  15.                    link + 'category/' + select.options[select.selectedIndex].value;
  16.            }
  17.            --></script>
  18.  
  19.             <select id="categories" onchange="onCatChange(this)" >
  20.                 <option value="all">All Events</option>
  21.                 <?php
  22.                foreach ($categories as $cat) {
  23.                    if (tribe_meta_event_category_name() == $cat->name) $selected='selected';
  24.                     else $selected = '';
  25.                 ?>
  26.                 <option value="<?= $cat->slug ?>" <?= $selected ?>><?= $cat->name ?></option>
  27.                 <?php } ?>
  28.             </select>
Advertisement
Add Comment
Please, Sign In to add comment