Created
October 25, 2013 03:46
-
-
Save jplhomer/7149180 to your computer and use it in GitHub Desktop.
The template to show our custom timeline using Wordpress and Advanced Custom Fields: http://jplhomer.org/2013/10/building-responsive-timeline-advanced-custom-fields/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( $events = get_field( 'events' ) ) : | |
// Re-order our events just in case | |
if ( get_field('sort_order') == 'Date Descending') { | |
usort( $events, 'sort_by_date_descending'); | |
} else { | |
usort( $events, 'sort_by_date_ascending'); | |
} | |
// Set a year checker to see if we should print a new year | |
$year = 0; | |
$is_new_year = false; | |
?> | |
<div class="timeline"> | |
<?php foreach ( $events as $idx => $event ) : | |
$is_new_year = false; | |
$event_year = date( "Y", strtotime( $event['event_date'] ) ); | |
if ( $year != $event_year ) { | |
$year = $event_year; | |
$is_new_year = true; | |
} | |
?> | |
<?php if ( $is_new_year ) { ?> | |
<?php if ( $idx > 0 ) { // If it's not the first event, we need to end the current list ?> | |
</ul> | |
<?php } ?> | |
<h2><?php echo $event_year; ?></h2> | |
<ul> | |
<?php } ?> | |
<li> | |
<h3><?php echo $event['event_title']; ?></h3> | |
<?php echo $event['event_description']; ?> | |
<time><?php echo date( "F Y", strtotime($event['event_date']) ); ?></time> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment