Skip to content

Instantly share code, notes, and snippets.

@ndmdn
Last active April 30, 2016 05:10
Show Gist options
  • Save ndmdn/af7436e159ac880b34d2 to your computer and use it in GitHub Desktop.
Save ndmdn/af7436e159ac880b34d2 to your computer and use it in GitHub Desktop.
An example of a WP Loop that builds a timeline page using ACF and CodyHouse Vertical CSS3 Timeline
function timeline_loop() {
$args = array(
'meta_key' => 'historical_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page'=> '100',
);
echo '<section id="cd-timeline" class="cd-container">';
$loop = new WP_Query( $args );
if( $loop->have_posts() ) {
// loop through posts
while( $loop->have_posts() ): $loop->the_post();
// Format the date string, for some reason ACF returning the string with duplicate Y values ie. 192219220101 hence the YYmd in the createFromFormat function
$date = DateTime::createFromFormat('YYmd', get_field('historical_date'));
echo '<div class="cd-timeline-block">';
echo '<div class="cd-timeline-img cd-picture">';
echo '<img src="img/cd-icon-picture.svg" alt="Picture">';
echo '</div>';
echo '<div class="cd-timeline-content">';
echo '<h2>' . get_the_title() . '</h2>';
echo '<p>' . get_the_excerpt() . '</p>';
echo '<a href="' . get_permalink() . '" class="cd-read-more">Read more</a>';
echo '<span class="cd-date">' . $date->format('F j, Y') . '</span>';
echo '</div>';
echo '</div>';
endwhile;
}
echo '</section>';
echo '<script src="timelinejs/main.js"></script>';
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment