Show day name in schedule details

Home Forums Calendar Products Events Calendar PRO Show day name in schedule details

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #945392
    magnusfriis
    Participant

    Hi,

    I want to show the name of the day together with the date on the list with events, e.g. ‘monday’, but can’t figure out how.

    Any suggestions?

    Thanks.

    #945489
    George
    Participant

    Hey Magnus,

    Thanks for reaching out to us. There are a few different ways to achieve what you’re looking to do here – it seems from your screenshot that you’ve already modified some of your Events Templates, is that correct?

    If so, then in those modified templates, you should be able to find where that Event Date is being generated and then just manually add some code that gets the “Day Name” from the event start date. To learn about getting Day Names from dates in PHP, read up about the date() function here → http://php.net/manual/en/function.date.php

    You can get the start date of the event itself by using some PHP like the following on a single-event template:

    
    // Gets the start date of this event.
    $this_event_meta       = get_post_meta( get_the_ID() );
    $this_event_start_date = $this_event_meta['_EventStartDate'][0];
    $start_date_day_name   = date( 'l', strtotime( $this_event_start_date ) );
    
    // Output the $start_date_day_name var where desired.
    echo $start_date_day_name;
    

    Another alternative is use a filter, which uses the same general idea as the code above. I wrote a quick code snippet for you that will do this only on the “List” view for events, although you can modify the conditional statements I’m using (or get rid of them) to let this filter suit your needs. To see a full list of conditionals for various views of The Events Calendar, see this Gist here → https://gist.github.com/jo-snips/2415009

    My specific code example for you can be seen in this Gist here → https://gist.github.com/ggwicz/130a40c2e9958c50cecf

    Play around with these options and be sure to save your changes as you go along – keep a backup of your site before starting to customize, and keep a backup of all customizations too! 🙂

    Let us know if this helps, cheers.

    George

    • This reply was modified 8 years, 7 months ago by George.
    #945865
    magnusfriis
    Participant

    That’s perfect – thanks a bunch!

    Is there a way I can translate it (in this case to danish) and can I make it short, like ‘mon’ instead of monday – or in danish – ‘mon’ instead of ‘mandag’.

    Best, Magnus

    #945922
    George
    Participant

    Hey Magnus,

    If you set your WordPress language to Danish, the Events Calendar will load its Danish translation files and should work well. There are several ways to translate WordPress, even certain plugins that can help, so I’d recommend learning more about that in general on a page like this one → http://codex.wordpress.org/WordPress_in_Your_Language

    As for using simpler day names, this may be possible – your best bet is to head to “Events > Settings > Display” in your WordPress admin, and find the section related to date formats → https://cloudup.com/cAjHiBu1XFd

    These letters there are not just random – they’re characters for the specific PHP date() function which is used to generate the date displays. You can see all the available options for this function here → http://php.net/manual/en/function.date.php

    As you can see on that page, shortened day names are indeed supported, so I’d recommend playing around with this in those Date Format options and see what you can come up with.

    Let me know if this helps – apologies if anything is too vague here, let me know if that’s the case.

    Cheers!
    George

    #946100
    magnusfriis
    Participant

    All right, thanks.

    It’s a multisite – one in Danish and one in English.
    My installation with the calendar is allready in Danish, and the month name and days are translated correct in the rest of the page and the mini widget calendar (in the top right corner – see page example). That’s why I don’t understand why it isn’t automatic in Danish?

    Thanks again for your help!

    #946210
    George
    Participant

    Hey Magnus,

    Just to be clear, in your last reply here, are you saying that instead of “Marts” in the area where your red arrow points to, it should say a shorter abbreviation of that month name?

    If so, what should this abbreviated month name be?

    If that is not an accurate description of what you’re looking for, I’m sorry for misunderstanding you! Try offering a little more detail if you can.

    Thanks for your patience Magnus!

    George

    #946263
    magnusfriis
    Participant

    Hi George,

    Sorry for the confusion. Let me try to explain it a bit better:

    I already have a section with the number of the day and month, e.g. ’22 marts’ (In English: ‘March 22nd’).
    What I want, is the name of the day combined with the example above. E.g. ‘Mandag 22 marts’ (In English: ‘Monday, March 22nd’).

    Your code worked like a charm, but is not translated like the rest of the page.
    My problem, therefore, is that the name of the day is in English even though the rest of the page is in Danish (Including The Events Calendar’s other functions).

    Does this make sense? Otherwise let me know, and I will try to explain again.

    Thanks for your patience too.

    Best, M

    #946544
    George
    Participant

    Hey Magnus,

    Thanks for your patience! I’m sorry I misunderstood your issue before, but do now – it’s a bit of a tricky issue, at least as far as I can think.

    The best option I can think of is, instead of using just PHP’s own date() function, trying another function that is built into WordPress Core – date_i18n(). You can learn about this function here → http://codex.wordpress.org/Function_Reference/date_i18n

    A quick [and admittedly un-tested 🙂 ] example off the top of my head would be instead of using this, which is from my example code up in my first reply to you:

    date( 'l', strtotime( $this_event_start_date ) );

    Try something like this:

    date_i18n( 'l', strtotime( $this_event_start_date ) );

    You can use all the same letter symbols for date formatting that are in the original PHP date() function overview page I shared with you earlier – play around with this a bit and read that Codex article about date_i18n(), and let me know if this helps at all.

    Cheers,
    George

    #946721
    magnusfriis
    Participant

    That’s just great, George. It works perfectly – thanks!

    #946961
    George
    Participant

    Cool – best of luck with your site!

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Show day name in schedule details’ is closed to new replies.