Skip to content

Instantly share code, notes, and snippets.

@jplhomer
Created October 25, 2013 03:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplhomer/7149180 to your computer and use it in GitHub Desktop.
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/
<?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