Home › Forums › Calendar Products › Events Calendar PRO › List View: Show date on only the first event of the day
- This topic has 7 replies, 2 voices, and was last updated 10 years, 6 months ago by
Brian.
-
AuthorPosts
-
October 28, 2015 at 12:45 pm #1019497
Percy
ParticipantHello,
I’ve searched the knowledge base and docs quite a bit and found nothing on this topic.
If I have several events on one day, the list view currently shows the date for each entry. I’d like to show the date once per day:
October 28, 2015
Event 1: 10am
Event 2: 11am
Event 3: 3pm
Event 4: 5pmOctober 29, 2015
Event 1: 11am
Event 2: 1pm
Event 3: 2pm
Event 4: 5pmThanks for your help.
October 29, 2015 at 7:46 am #1019759Brian
MemberHi,
Thanks for using our plugins. I can try to help out here.
This is an interesting request, but not something we support out of the box.
It could be possible with a customization, but for the most part that is beyond the support we can provide.
We do have the themer’s guide for editing our templates:
https://theeventscalendar.com/knowledgebase/themers-guide/
I can try to answer a question or two to get started.
Let me know.
Thanks
October 29, 2015 at 9:01 am #1019816Percy
ParticipantThanks for the reply Brian. I’d be interested to hear any clues you might have as to which functions would need to be modded to achieve this.
I already looked at list/loop.php and list/single-event.php but couldn’t find anything specific enough, so I’m guessing it’s in a function.
Thanks
October 29, 2015 at 12:28 pm #1019987Brian
MemberWe really do not have a function for it.
You might be able to use some php like this to get the date for each event.
$startDate = strtotime( get_post_meta( $event_id, '_EventStartDate', True ) );
$startDate = date( 'Y-m-d', $startDate );
You could create a global and if the dates match do not display it.
Once the dates do not match you could then show the date again and update the global variable.
October 29, 2015 at 1:10 pm #1020020Percy
ParticipantThanks for this Brian.
October 29, 2015 at 1:32 pm #1020028Brian
MemberYou’re Welcome.
If you get into it and get stuck I might be able to help out one more time.
Thanks
October 31, 2015 at 1:48 am #1020468Percy
ParticipantIt worked!
In case anyone else needs this, here’s the modded code for list/loop.php. Look for “Start listview date mod” in the code comments:
<?php while ( have_posts() ) : the_post(); ?> <!-- Month / Year Headers --> <?php tribe_events_list_the_date_headers(); ?> <!-- Start listview date mod part 1/2 --> <!-- Get Event ID (same as post ID in WP) --> <?php $event_id = get_the_ID(); ?> <!-- Convert Event ID to human readable date--> <?php $startDate = strtotime( get_post_meta( $event_id, '_EventStartDate', True ) ); $startDate = date( 'l F jS', $startDate ); ?> <?php do_action( 'tribe_events_inside_before_loop' ); ?> <!-- Compare $test to $startDate and only publish if theylre different --> <?php if($test !=$startDate): ?> <h2 class="event-date-once" ><?php echo $startDate;?></h2> <?php endif; ?> <!-- End listview date mod part 1/2 --> <!-- Event --> <?php $post_parent = ''; if ( $post->post_parent ) { $post_parent = ' data-parent-post-id="' . absint( $post->post_parent ) . '"'; } ?> <div id="post-<?php the_ID() ?>" class="<?php tribe_events_event_classes() ?>" <?php echo $post_parent; ?>> <?php tribe_get_template_part( 'list/single', 'event' ) ?> </div><!-- .hentry .vevent --> <?php do_action( 'tribe_events_inside_after_loop' ); ?> <!-- Start listview date mod part 2/2 --> <!-- pass startDate into a variable $test that will be used to compare to the new $startDate at the top of the loop. Only dates that differ will publish --> <?php $test = $startDate?> <!-- End listview date mod part 2/2 --> <?php endwhile; ?>And here’s the code that strips the date away as well as the ‘@’ (leaving only the start and end time of the event)– add it to list/single-event.php:
<!-- Removes Date info and publishes time only --> <div class="updated published time-details"> <?php $stripDate = tribe_events_event_schedule_details() ?> <?php $stripDate = strstr($stripDate, '@'); $stripDate = str_replace("@", "", $stripDate); echo $stripDate; ?> </div>I did not accommodate for events that span from one day to another nor events that span over several days. We don’t seem to need that at the moment.
Thanks for steering me in the right direction.
November 2, 2015 at 6:23 am #1020727Brian
MemberThanks for sharing!
I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.
Thanks!
-
AuthorPosts
- The topic ‘List View: Show date on only the first event of the day’ is closed to new replies.
