Support

Home Forums Event Espresso Premium Splitting the date on latest events lists in EE3

Splitting the date on latest events lists in EE3

Posted: October 9, 2014 at 4:06 am

Viewing 17 reply threads


Spen

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


Spen

October 9, 2014 at 4:08 am

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


Dean

October 9, 2014 at 5:46 am

Hi,

It’s possible but you will need to edit the event_list_display.php template file.

First off copy these two files
/wp-content/plugins/event-espresso_31366/templates/event_list_display.php
/wp-content/plugins/event-espresso_31366/templates/event_list.php

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] . '';
 ?>  


Dean

October 9, 2014 at 5:48 am

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


Spen

October 10, 2014 at 5:55 am

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>’;
echo ‘ ‘;
echo ‘<span>’ . $x[1] . ‘</span>’;

Which outputs:

<span class=”month”>Oct, 15</span>
<span></span>

Sorry for being dense, but I can’t see how to divide the month and day.


Tony

  • Support Staff

October 13, 2014 at 1:01 am

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)

http://take.ms/D8n82


Spen

October 13, 2014 at 4:28 am

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>’;
echo ‘ ‘;
echo ‘<span=”day”>’ . $x[1] . ‘</span>’;

?>

I would also be keen to remove the comma itself.

Cheers Tony,

Spencer


Spen

October 13, 2014 at 4:29 am

This is the result I am getting:

<span=”month”>Nov,20 <span=”day”> </span=”day”>
</span=”month”>

Odd, eh?


Dean

October 13, 2014 at 4:37 am

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.


Spen

October 13, 2014 at 5:23 am

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


Tony

  • Support Staff

October 13, 2014 at 7:59 am

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)


Spen

October 13, 2014 at 8:22 am

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>’;
echo ‘ ‘;
echo ‘<span=”day”>’ . $x[1] . ‘</span>’;


Dean

October 13, 2014 at 9:17 am

Hi,

echo β€˜β€™ . $x[0] . β€˜β€™;
echo β€˜ β€˜;
echo β€˜β€™ . $x[1] . β€˜β€™;

should be

http://pastebin.com/SC24TYg7

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

  • This reply was modified 10 years, 1 month ago by Dean. Reason: code edit
  • This reply was modified 10 years, 1 month ago by Dean. Reason: another code edit


Spen

October 13, 2014 at 10:26 am

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! πŸ˜€


Tony

  • Support Staff

October 14, 2014 at 3:58 am

Hi Spencer,

Is this working as expected now?


Spen

October 14, 2014 at 6:12 am

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


Dean

October 14, 2014 at 6:31 am

Glad to hear it’s working now. Are we ok to mark this thread as resolved?


Spen

October 14, 2014 at 6:38 am

Yes, please do.

Spencer

Viewing 17 reply threads

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.

Event Espresso