Place the filter bar after the title

Home Forums Calendar Products Filter Bar Place the filter bar after the title

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1592682
    deodat
    Participant

    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

    #1592686
    deodat
    Participant

    This reply is private.

    #1594059
    Sky
    Keymaster

    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

    #1594502
    deodat
    Participant

    This reply is private.

    #1594514
    deodat
    Participant

    This reply is private.

    #1594584
    deodat
    Participant

    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 );
    #1594591
    deodat
    Participant

    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.

    #1594886
    Sky
    Keymaster

    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

    #1595274
    deodat
    Participant

    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

    #1595275
    deodat
    Participant

    This reply is private.

    #1595276
    deodat
    Participant

    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

    #1596099
    Sky
    Keymaster

    David,

    Great, glad you got it figured out.

    Take care,
    Sky

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Place the filter bar after the title’ is closed to new replies.