Previous/Next month events show in Current month view

Home Forums Calendar Products Events Calendar PRO Previous/Next month events show in Current month view

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1300370
    Thomas
    Participant

    Hi,

    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.

    #1301412
    Barry
    Member

    Hi 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 🙂

    #1301555
    Thomas
    Participant

    Hi 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 !

    #1301569
    Thomas
    Participant

    Hello 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 ?

    #1301657
    Barry
    Member

    I 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!

    #1301662
    Thomas
    Participant

    Yes of course I won’t risk changing the plugin core files !
    Thanks a lot, again 🙂

    #1301967
    Barry
    Member

    Awesome – good luck with the project!

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Previous/Next month events show in Current month view’ is closed to new replies.