Created
June 14, 2018 22:28
-
-
Save KreigD/1de07096da7d24b2ab2b4988b278ecd2 to your computer and use it in GitHub Desktop.
Flickity WordPress Carousel
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 | |
/** | |
* Flickity-based carousel for returning posts from the loop. I find it far more versatile and simple than a Bootstrap | |
* carousel. Get the required scripts and styles from here: https://flickity.metafizzy.co/ | |
*/ | |
<div class="blog-carousel"> | |
<?php | |
if ( have_posts() ) : while ( have_posts() ) : the_post(); | |
$thumbnail_id = get_post_thumbnail_id(); | |
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'large', true ); | |
?> | |
<div class="carousel-cell"> | |
<!-- I chose to display my posts in a custom card style. --> | |
<article class="article-card"> | |
<a href="<?php the_permalink(); ?>"><img src="<?php echo $thumbnail_url[0]; ?>" alt="<?php the_title(); ?>" class="card-img"></a> | |
<div class="card-content"> | |
<a href="<?php the_permalink(); ?>" class="article-title"><?php the_title( "<h4>", "</h4>" ) ?></a> | |
</div> | |
<footer class="card-footer"> | |
<a href="<?php the_permalink(); ?>" class="button purple-outline" role="button">Learn More</a> | |
</footer> | |
</article> | |
</div> | |
<?php | |
endwhile; | |
endif; | |
wp_reset_query(); | |
?> | |
</div> | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment