Posted: October 9, 2014 at 4:06 am
|
Hello there, Is it possible to split the date apart so each element can be styled individually? For example, I would like to do this: <span class=”day”>{DATE[j]}</span><span class=”month”>{DATE[M]}</span> I know events in EE3 are not actual posts, so my previous method does not work. Cheers, Spencer |
|
Whoops, I should have tidied my example: {DATE[j]} is from a plugin I have used, but the point is that I am trying to divide month and day into their own containers. Cheers, Spencer |
|
Hi, It’s possible but you will need to edit the event_list_display.php template file. First off copy these two files over to wp-content/uploads/espresso/templates This will stop updates from over writing the changes. In that uploads location, edit the event_list_display.php file and look for This needs to be changed to something like the following (the below code will need to be changed based on your date format and needs, but it should give you a rough idea)
' . $x[0] . '';
echo ' ';
echo '' . $x[1] . '';
?>
|
|
Sorry I should add that my initial date format is: November 8, 2014 That will help explain why I am breaking the date based on a comma and space |
|
Thanks Dean, I am trying to split month and date. I added a couple of spans around the date: echo ‘<span class=”month”>’ . $x[0] . ‘</span>’; Which outputs: <span class=”month”>Oct, 15</span> Sorry for being dense, but I can’t see how to divide the month and day. |
Hi Spencer, What date format are you using? Did you include this line of code: $x = explode(', ', $x); explode() takes a string and builds an array from that string, each element of the array is determined by the delimiter (in this case a comma and a space – ‘, ‘) So if you explode() “Oct, 15” you should have: array (size=2) 0 => string 'Oct' (length=3) 1 => string '15' (length=2) |
|
|
Hi Tony, Yes, I have tried the following: <?php $x = event_date_display($start_date, get_option(‘date_format’)); $x = explode(‘, ‘, $x); echo ‘<span=”month”>’ . $x[0] . ‘</span>’; ?> I would also be keen to remove the comma itself. Cheers Tony, Spencer |
|
This is the result I am getting: <span=”month”>Nov,20 <span=”day”> </span=”day”> Odd, eh? |
|
Hi, Without knowing the exact date format you are using it’s hard to say, but you could try $x = explode(‘,’, $x); Which will just split the content via commas. If that doesn’t work, please let us know your full date format, e.g. Nov 20th 2014 or Monday November 20, 2014 etc etc. |
|
Hey Dean, Oh dar, sorry I thought I listed the date format as: M,j Ultimately, I am trying to split the date Oct, 15 and remove the comma. Sorry for being a pain, I’m still learning the basics of PHP at the mo π Thanks again, Spencer |
The date format M,j will output “Oct,15” So as @Dean mentions, you’ll need to use $x = explode(',', $x); Notice there is no space after the comma (as your date string doesn’t have one) |
|
|
Great, thanks Tony. The weird thing here is the html output. Am I not wrapping the span classes correctly? <span=”month”>Nov <span=”day”>13</span=”day”></span=”month”> I used the following code, and removed the space after the comma: $x = event_date_display($start_date, get_option(‘date_format’)); $x = explode(‘,’, $x); echo ‘<span=”month”>’ . $x[0] . ‘</span>’; |
|
Hi,
echo ββ . $x[0] . ββ;
echo β β;
echo ββ . $x[1] . ββ;
should be Added the code to pastebin as our forum is playing up currently. I swapped id for class as you will use it more than once |
|
Man, I just noticed I gave you my example with <span=βmonthβ> minus the class… thanks for your patience dealing with this kind of idiocy! π |
Hi Spencer, Is this working as expected now? |
|
|
Hi Tony, Yes, it works perfectly. Thanks a million for your help, it was wrecking my head! As I said, I’m still an entry level PHP head so am very much still learning the ropes. Spencer |
|
Glad to hear it’s working now. Are we ok to mark this thread as resolved? |
|
Yes, please do. Spencer |
The support post ‘Splitting the date on latest events lists in EE3’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.