Home › Forums › Calendar Products › Filter Bar › Place the filter bar after the title
- This topic has 11 replies, 2 voices, and was last updated 5 years, 8 months ago by deodat.
-
AuthorPosts
-
August 8, 2018 at 1:20 am #1592682deodatParticipant
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
August 8, 2018 at 1:35 am #1592686deodatParticipantThis reply is private.
August 9, 2018 at 10:33 am #1594059SkyKeymasterHi 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,
SkyAugust 10, 2018 at 2:44 am #1594502deodatParticipantThis reply is private.
August 10, 2018 at 3:02 am #1594514deodatParticipantThis reply is private.
August 10, 2018 at 5:02 am #1594584deodatParticipantI 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 );
August 10, 2018 at 5:40 am #1594591deodatParticipantwhen 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.
August 10, 2018 at 9:42 am #1594886SkyKeymasterHi 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,
SkyAugust 11, 2018 at 1:14 am #1595274deodatParticipantHi 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
August 11, 2018 at 1:26 am #1595275deodatParticipantThis reply is private.
August 11, 2018 at 1:38 am #1595276deodatParticipantSky,
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
August 13, 2018 at 7:57 am #1596099SkyKeymasterDavid,
Great, glad you got it figured out.
Take care,
Sky -
AuthorPosts
- The topic ‘Place the filter bar after the title’ is closed to new replies.