Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By computerbarry on
Hi all
With the below code I select some entities no older than today.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'whats_on')
->entityCondition('bundle', 'events')
->fieldCondition('field_event_date_time', 'value', date("Y-m-d"), '>') // Show events no earlier than today
->fieldOrderBy('field_event_date_time', 'value', 'ASC')
Is it possible to show events only for this week, meaning, I'll need to somehow track what day it is and display only the events for the days remaining till Sunday.
Example:
If today is Friday, we only show events for Friday, Saturday and Sunday (only 3 days left in this week).
Is this something we can do with fieldCondition, maybe a small snippet of PHP we can add above as shown below, which I did try but only shows events after 7 days?
->fieldCondition('field_event_date_time', 'value', date("Y-m-d",strtotime("+1 week")), '>')
Thanks, Barry
Comments
Have you tried<?php$query =
Have you tried
Well spotted!
Good call.
This is working, now I have events showing for the next 7 days looks good :)
Now within these events I'm getting results from Tuesday, Wednesday next week.
How do I only show events for this week? Maximum return should be Sunday/Monday morning.
I could easily add strtotime("+3 days"), though come tomorrow this would be invalid.
Thanks, Barry
The more you learn.... the more you learn there is more to learn.
How about
Perfect!
Perfect!
Works great Nevets, just what I wanted :)
Thank you!
The more you learn.... the more you learn there is more to learn.
Out of curiosity, and no
Out of curiosity, and no doubt an issue maybe further down the line.
What happens if not events are available for this week, would that mean no events are shown, or events for next will show as default?
Thanks, Barry
The more you learn.... the more you learn there is more to learn.
No events would be shown.
No events would be shown.
Ok.
Ok.
Would it possible to code this in so we show the next available week?
Or maybe just add a else if and show a simple message "No events this week"
Thanks, Barry
The more you learn.... the more you learn there is more to learn.
As part of the code not shown
As part of the code not shown, you execute the query, then loop through the results to list the events. You can enhance that code so if there are no results you print a message.
I've changed the dates of the
I've changed the dates of the events and you're right, nothing shows.
I tried adding if else myself, no idea where I should place this.
Can you advise nevets, just can't figure out where I should code this in.
Is it something to do with items at the bottom?
We just need to drop in something like:
Thanks, Barry
The more you learn.... the more you learn there is more to learn.
I've managed to display the
I've managed to display the string using:
Though this is now showing outside of all my html straight after the opening body tag, is this the correct way?
How do I add this message inside the below output so everything sits inside the container with the title?
Thanks, barry
The more you learn.... the more you learn there is more to learn.
Can anybody help with this?
Can anybody help with this?
I just read over on theme_item_list api comments:
This is exactly what's happening when no events are returned for this week
My markup:
So how can we feed in the no events message into a new < li > when the array is empty?
Thanks, barry
The more you learn.... the more you learn there is more to learn.
<?php $items = array();
Fantastic! Thanks a lot
Fantastic! Thanks a lot Jaypan.
Working perfectly. I should know this this by now all the work we've done :)
I also added another class into the mix:
Thank you!
Barry
The more you learn.... the more you learn there is more to learn.
You should wrap 'no events
You should wrap 'no events found' in the t() function.
Good catch thanks.
Good catch thanks.
Updated!
Barry
The more you learn.... the more you learn there is more to learn.