custom theme : get the displayed date in day view

Home Forums Calendar Products Events Calendar PRO custom theme : get the displayed date in day view

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #956406
    Nicolas
    Participant

    Hi and thanks for the awesome plugin.

    I can’t manage to do something that might be simple, and can’t find a working solution in the forums or in the API documentation… Then I ask you for some help.

    I builded a custom template for the day view (day.php). I need to get the date of the actually viewed day (which can be today or another if the user has clicked on a day link in the mini-calendar widget).

    Then I would be able to highlight or not a navigation link (“Today’s events”) and highlight the actual viewed day in the mini-calendar widget.

    But I can’t find a way to get the actually displayed day as a simple date.
    Can you help me with this ?

    Thanks !

    #956432
    George
    Participant

    Hey Nicolas,

    Thanks for reaching out to us! If I understand your request accurately, then this should be quite simple to do – basically, wherever you want the Day name of the various date to show up, you should be able to use code like the following:

    
    $date = tribe_get_event_meta( get_the_ID(), '_EventStartDate', true );
    echo date( 'l', strtotime( $date ) );
    

    The first line gets the start date of the event you’re currently on, and then the second line displays the full name of the day (e.g. “Thursday”, or “Saturday”, etc.) using PHP’s date() function.

    Learn more about the date() function here → http://php.net/manual/en/function.date.php

    Play around with this and let us know if it helps! 🙂

    Cheers,
    George

    #956467
    Nicolas
    Participant

    Hello,

    Thanks for your answer but that’s not at all a response to the question I submitted 🙂
    Maybe my explanation wasn’t understandable and I’me sorry for this.

    I need to get the date of the day that is actually displayed in the “day view” list (date.php file of tribe events views), then we are not inside an event but on the day events list.

    As I use the mini-calendar pro widget, visitors can click on a day in the calendar and view all the events for the day they want in the day view (plugins/the-events-calendar/views/day).

    How can I get the date of the actually viewed day in the day view, that was my question.
    I will use this data to highlight some navigation and calendar elements, then I need to know if the visitor is actually viewing the events in day viw list for today or for another date.

    Is it clearer for you ?
    Thanks for your help !

    #957220
    George
    Participant

    Hi Nicolas,

    I’m sorry for the confusion here! I am indeed having some trouble understanding what you’re looking to do here, both in your updated post here and in your original one:

    I need to get the date of the actually viewed day

    Sorry for the misunderstanding!

    Would you be able to elaborate just a bit more on exactly what behavior you currently have on your site, and then in what ways you want it to be different? Take screenshots and annotate them if possible, or anything else you can think of!

    This is a code customization issue, which we can only provide very limited support for, but I’ll try giving your response another go and see if I can help. Thanks for being patient with my confusion here – I’m really sorry for the misunderstanding!

    Thank you,
    George

    #958008
    Nicolas
    Participant

    Hi George and thanks for your attention.
    I’m not a native english speaker and it’s sometimes hard to explain such things.

    Here is the situation :

    – My site uses Events Calendar Pro and the mini-calendar widget

    – Please imagine that a user clicks on a date in the minicalendar widget, let’s say for example that he clicks on June 28, 2015.

    – The click opens a page with an url like http://www.mysite.com/events/2015-06-28/.
    This view is called “the day view” in all your own documentation.
    Thsi view displays all the events of a chosen day as a list.

    – I want to be able to retrieve (get), with PHP, the information about the date that the user is on.
    In our case : “2015-06-28”.

    – with this data (“2015-06-28”), I can php code some conditions in my page (highlight this date in the mini-calendar, change the page title and include the date in, etc).

    I can get this info from the url, but maybe there is a cleaner solution to do this ?
    I was expecting that a function like tribe_get_viewed_date() or something like this, but can’t find such functions in your docs.

    Can you help me getting the date of the day the user is viewing in the day view ?

    I hope this explanation is better that the last ones ? I don’t know how to say it better…
    Is it understandable for you ?

    #958143
    George
    Participant

    Hey Nicolas,

    Thank you for elaborating on your needs here! The language barrier can indeed be hard to work around sometimes, and I appreciate your patience and willingness to clarify things here. Thank you!

    Fortunately, what you’re looking to here should indeed be possible. It may seem complicated, but trust me, the following things are quite simple.

    Writing custom code

    First, you’ll want to make a custom “Day” view for events within your theme – this way, you can write custom code in this custom day view without breaking anything in the original plugin, and you can update the plugin without having to worry about the updates breaking anything either.

    To learn how to make a custom day view, read about the principles of this in our official themer’s guide here → https://theeventscalendar.com/knowledgebase/themers-guide/

    Then just apply those ideas to the file in your copy of The Events Calendar called views/day/single-event.php. So, just copy this file into a new folder and file path in your theme called /tribe-events/day/single-event.php.

    Once you have this duplicate file in your theme so you can customize it.

    Accessing the day’s date

    Whenever you’re on a given “day” events list, you can access the date anywhere in that custom /day/single-event.php file by using the following one line of code:

    
    $current_day_date = strtotime( get_query_var( 'eventDate' ) );
    

    Now, you have the variable $current_day_date that you can then drop anywhere in the file with PHP’s date() function, which lets you pull specific date elements if you pass the $current_day_date variable to it.

    To learn all the specific elements from PHP’s date() function that you can use, read its full documentation here → http://php.net/manual/en/function.date.php

    A quick example

    For a quick example of this, look at the following screenshot of some date-related code I added in my theme’s custom /day/single-event.php file → https://cloudup.com/cuHc10EnRPL

    Here’s how this looks on the front-end of the site → https://cloudup.com/cauPVgOfrpM

    It uses the ‘z’ parameter for the PHP date() function – play around with this stuff a while and you should be able to get the hang of it for your custom code needs.

    I hope this helps – let us know if it does!

    Thanks,
    George

    #958297
    Nicolas
    Participant

    Dear George, I thank you very much !

    Your answer has much details, big thanks for the example script you made ! You understood my problem and I was able to solve it easily with your solution as it works in every place I needed it (including /mytheme/tribe-events/modules/bar.php and /mytheme/tribe-events/pro/widgets/mini-calendar/single-day).

    Then I can trash my “dirty” solution related on the page url…
    Once again big thanks, great support, problem solved !

    Best regards,
    Nicolas

    #958583
    George
    Participant

    Awesome! Glad to hear it Nicolas!

    Be sure to make backups of that custom code, and backups of your site and database in general. Best of luck with your project 🙂

    George

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘custom theme : get the displayed date in day view’ is closed to new replies.