Home › Forums › Calendar Products › Events Calendar PRO › Previous/Next month events show in Current month view
- This topic has 7 replies, 2 voices, and was last updated 8 years, 10 months ago by
Thomas.
-
AuthorPosts
-
June 20, 2017 at 2:10 am #1300370
Thomas
ParticipantHi,
I’ve added the tribe-events folder in my theme in order to modify the month view to show a list of the events and not a calendar.
The thing is that list is still showing events from the previous and next month (just like in a calendar view, it shows the events that are in the same week than the first day of the month (same for the end of the month))How can I do to only show events from the current month and not from previous or next ?
Thanks.
June 21, 2017 at 4:04 pm #1301412Barry
MemberHi Thomas,
Sounds like an interesting customization!
I do need to note first of all that the amount of support we can offer for custom dev tasks like this does tend to be limited, but I’d be happy to point you in the right direction if I can.
There are a few ways this might be tackled but perhaps the easiest (bearing in mind I don’t have access to your code and can’t see what you’ve set up already) would simply be to compare the date of each event to the date of the requested month: you could then render or skip to the next event appropriately.
That does of course mean some unnecessary expense is incurred (because behind the scenes, The Events Calendar would still be querying for events from the start and end of the adjacent months) – but on the other hand it may well be the easiest and most maintainable strategy.
Let me know what you think/if you have further questions 🙂
June 22, 2017 at 12:26 am #1301555Thomas
ParticipantHi Barry,
Thanks for your answer.
Actually I didn’t do much except call the single-event.php from the list folder instead of the single-event.php from the month folder. I just changed the HTML in order to customize the CSS as intended.So you think the easiest option is to override/hook the “main” loop function to only take events that matches the current month ? Is it possible for you to show me this hook ?
I’m going to search on my own and if I find anything before you answer I will let you know. Thanks a lot for your answer !
June 22, 2017 at 1:22 am #1301569Thomas
ParticipantHello again,
I’ve managed to do what I wanted !
I didn’t override or hook the main loop but I used 2 functions to get the current month that is displayed and the month of the current event in the loop.It works like this (in single-day.php) :
$month_of_event = split(‘-‘,$day[‘date’])[0].’-‘.split(‘-‘,$day[‘date’])[1];
$month_displayed = split(‘-‘,tribe_get_month_view_date())[0].’-‘.split(‘-‘,tribe_get_month_view_date())[1];<?php if($month_of_event == $month_displayed): ?>
/// SOME HTML ///
<?php tribe_get_template_part( ‘list/single’, ‘event’ ) ?>
/// SOME HTML ///
<?php endif; ?>It does what I want but do you think it’s the best solution or is it safer to override the month loop itself in functions.php ?
June 22, 2017 at 6:25 am #1301657Barry
MemberI think that’s fine – as noted before arguably the very best solution would be modifying the queries used to compose month view so we don’t query for those events at all (then you wouldn’t need this), but for a number of reasons that would be more complicated and harder to execute than doing something similar for a different type of view such as regular list view.
With that in mind, if this gets you the end result you’re looking for (and it seems like a safe customization to me – so long of course as those changes are in template overrides within your theme or child theme) we should be good to go!
June 22, 2017 at 6:34 am #1301662Thomas
ParticipantYes of course I won’t risk changing the plugin core files !
Thanks a lot, again 🙂June 22, 2017 at 2:38 pm #1301967Barry
MemberAwesome – good luck with the project!
-
AuthorPosts
- The topic ‘Previous/Next month events show in Current month view’ is closed to new replies.
