Help Desk

Place the filter bar after the title

  • Posts: 11 Topics: 3
    | Permalink

    Hi,

    I’d like to place the filter bar after the title and not before when I choose to display it horizontally.

    I’ve found the line to change in /the-events-calendar-filterbar/src/Tribe/View.php (lines 221 to 234) :

    			
    $show_filter = apply_filters( 'tribe_events_filters_should_show', in_array( get_post_type(), array( Tribe__Events__Main::VENUE_POST_TYPE, Tribe__Events__Main::ORGANIZER_POST_TYPE ) ) ? false : true );
    
    			if ( $show_filter ) {
    				// Only display filters before template if the layout is horizontal
    				if ( tribe_get_option( 'events_filters_layout', 'vertical' ) == 'vertical' ) {
    					add_action( 'tribe_events_bar_after_template', array( $this, 'displaySidebar' ), 25 );
    				} else {
    					if ( tribe_get_option( 'tribeDisableTribeBar', false ) == true ) {
    						add_action( 'tribe_events_before_template', array( $this, 'displaySidebar' ), 25 );
    					} else {
    						add_action( 'tribe_events_bar_after_template', array( $this, 'displaySidebar' ), 25 );
    					}
    				}
    			}
    

    in changing :

    add_action( 'tribe_events_before_template', array( $this, 'displaySidebar' ), 25 );
    

    to

    add_action( 'tribe_events_after_the_title', array( $this, 'displaySidebar' ), 25 );
    

    but I don’t know how to do this properly šŸ™‚

    could you help me with that ?

    thanks,

    regards,

    DAvid

    Posts: 11 Topics: 3
    | Permalink
    This reply has been marked as private.
    Posts: 2364
    | Permalink

    Hi there,

    Thanks for reaching out. Please note that we are limited in the amount of support we can provide for customizations such as this. That being said, I will try to help get you pointed in the right direction.

    I think there is a better way to approach this customization than what you are trying to do. It is not advisable to directly edit the plugin files, as your modifications will be lost when you update.

    Fortunately, our plugins are built with customization in mind. There are two ways you can safely customize the event views. All of our event views have templates that can be easily overridden by placing the modified copy of the file in your child theme within a “tribe-events” folder. You can read more about working with custom templates in our Themer’s Guide.

    The other way to safely make modifications is through the use of filters. Most of the markup that gets returned from our class methods and functions have filters applied to the return value. This means that you can change the output from your functions.php file without having modify the plugin files or event create a custom template. You can read more about WordPress filters here: https://developer.wordpress.org/plugins/hooks/filters/

    Additionally, in your case I wonder if this couldn’t be achieved by just creating a custom WordPress template instead of doing any of the above. Can you tell me more about what you mean “Iā€™d like to place the filter bar after the title and not before?” When using the Twenty Seventeen theme, I do not see any titles after the filterbar. There is an “Upcoming Events” title before the filterbar, and it sounds like this is what you are trying to achieve.

    Do you have a link to your site where I can see what you’re wanting to modify? Or, can you provide a screenshot showing the title that is coming after the filter bar?

    Thanks,
    Sky

    Posts: 11 Topics: 3
    | Permalink
    This reply has been marked as private.
    Posts: 11 Topics: 3
    | Permalink
    This reply has been marked as private.
    Posts: 11 Topics: 3
    | Permalink

    I managed to remove the filter bar like this :

    remove_action( 'wp_enqueue_scripts', array( Tribe__Events__Filterbar__View::instance(), 'enqueueStylesAndScripts' ), 11 );

    but I can’t manage to add it after that with a custom Class like this :

    class MyTheme__Events__Filterbar__View extends Tribe__Events__Filterbar__View {
        public function enqueueStylesAndScripts() {
            
            ... some original code ...
    
            $show_filter = apply_filters( 'tribe_events_filters_should_show', in_array( get_post_type(), array( Tribe__Events__Main::VENUE_POST_TYPE, Tribe__Events__Main::ORGANIZER_POST_TYPE ) ) ? false : true );
    
            if ( $show_filter ) {
                // Only display filters before template if the layout is horizontal
                if ( tribe_get_option( 'events_filters_layout', 'vertical' ) == 'vertical' ) {
                    add_action( 'tribe_events_bar_after_template', array( $this, 'displaySidebar' ), 25 );
                } else {
                    if ( tribe_get_option( 'tribeDisableTribeBar', false ) == true ) {
                        add_action( 'tribe_events_after_the_title', array( $this, 'displaySidebar' ), 25 ); // MY OVERRIDE
                    } else {
                        add_action( 'tribe_events_bar_after_template', array( $this, 'displaySidebar' ), 25 );
                    }
                }
            }
    
            ... some original code ...
    
        }
    
    }
    
    add_action( 'wp_enqueue_scripts', array( MyTheme__Events__Filterbar__View::instance(), 'enqueueStylesAndScripts' ), 11 );
    Posts: 11 Topics: 3
    | Permalink

    when I’m adding all the original code of the Tribe__Events__Filterbar__View Class (with just my override), it quite works … but my filter is displayed twice šŸ™

    I don’t understand why.

    Posts: 2364
    | Permalink

    Hi again,

    Unfortunately, I am not able to see your site. The login credentials you provided are not working for me.

    In any case the approach you are taking above should not be necessary. The filter bar is output in the templates with a simple function, and all you need to do is move where the function is called.

    tribe_get_template_part( 'modules/bar' );
    

    The above code is all that is needed to output the filter bar. To change the location, just find this in the template you want to modify, and move to where you want it.

    If you can provide me with a screenshot of the view you are trying to modify, I will tell you which template to copy into your child theme and make your changes in.

    Thanks,
    Sky

    Posts: 11 Topics: 3
    | Permalink

    Hi Sky,

    I’m sorry but I’m confused here because, for me, this template part is not for the filter bar but for the Events Navigation Bar (located here : /the-events-calendar/src/views/modules/bar.php).

    I can’t find something similar in The Events Calendar Filterbar plugin.

    The only chunk of code where I can move this filter bar is the one I indicated earlier :

    the-events-calendar-filterbar/src/Tribe/View.php

            if ( $show_filter ) {
                // Only display filters before template if the layout is horizontal
                if ( tribe_get_option( 'events_filters_layout', 'vertical' ) == 'vertical' ) {
                    add_action( 'tribe_events_bar_after_template', array( $this, 'displaySidebar' ), 25 );
                } else {
                    if ( tribe_get_option( 'tribeDisableTribeBar', false ) == true ) {
                        add_action( 'tribe_events_after_the_title', array( $this, 'displaySidebar' ), 25 ); // MY OVERRIDE
                    } else {
                        add_action( 'tribe_events_bar_after_template', array( $this, 'displaySidebar' ), 25 );
                    }
                }
            }

    But it will be great indeed if I could just use a template part.

    I give you my credentials in the next private message.

    Regards,

    David

    Posts: 11 Topics: 3
    | Permalink
    This reply has been marked as private.
    Posts: 11 Topics: 3
    | Permalink

    Sky,

    You put me on the road.

    This actually works for me :

    In functions.php :

    remove_action( 'wp_enqueue_scripts', array( Tribe__Events__Filterbar__View::instance(), 'enqueueStylesAndScripts' ), 11 );

    and in the modified and copied title-bar.php template :

    <?php tribe_get_template_part( 'filter-bar/filter-view-horizontal' ); ?>

    easy peasy šŸ™‚

    Thanks a lot,

    David

    Posts: 2364
    | Permalink

    David,

    Great, glad you got it figured out.

    Take care,
    Sky

    | Permalink