jmccole83
1/30/2019 - 9:07 AM

The Events Caledar plugin - custom view switch

Use below snippet to develop your own custom view switch bar, outputs views as <a> tags instead of form options. Output is also conditional, only added to the page if there is more than 1 active view on the site.

@php $views = tribe_events_get_views() @endphp

    @if ( count( $views ) > 1 )

    <div class="switch-view">

      <span>View as:</span>

      @foreach ( $views as $view )
        @php printf(
          '<a class="switch %2$s" href="%1$s" data-view="%2$s"%3$s>%4$s</a>',
          esc_attr( $view['url'] ),
          esc_attr( $view['displaying'] ),
          tribe_is_view( $view['displaying'] ) ? ' selected' : '',
          esc_html( $view['anchor'] )
        ) @endphp
      @endforeach

    </div>

    @endif