List View: Show date on only the first event of the day

Home Forums Calendar Products Events Calendar PRO List View: Show date on only the first event of the day

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1019497
    Percy
    Participant

    Hello,

    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: 5pm

    October 29, 2015
    Event 1: 11am
    Event 2: 1pm
    Event 3: 2pm
    Event 4: 5pm

    Thanks for your help.

    #1019759
    Brian
    Member

    Hi,

    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

    #1019816
    Percy
    Participant

    Thanks 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

    #1019987
    Brian
    Member

    We 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.

    #1020020
    Percy
    Participant

    Thanks for this Brian.

    #1020028
    Brian
    Member

    You’re Welcome.

    If you get into it and get stuck I might be able to help out one more time.

    Thanks

    #1020468
    Percy
    Participant

    It 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.

    • This reply was modified 10 years, 6 months ago by Percy. Reason: typos
    • This reply was modified 10 years, 6 months ago by Percy.
    #1020727
    Brian
    Member

    Thanks 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!

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘List View: Show date on only the first event of the day’ is closed to new replies.