-
-
Save boywondercreative/96f063a00c0c4fb6cbf2df2b09b3700c 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