Skip to content

Instantly share code, notes, and snippets.

@solid-pixel
Last active January 25, 2021 16:03
Show Gist options
  • Save solid-pixel/91a8a21af562d472030add421b4a3861 to your computer and use it in GitHub Desktop.
Save solid-pixel/91a8a21af562d472030add421b4a3861 to your computer and use it in GitHub Desktop.
Display WordPress Custom Posts with Bootstrap 4 Cards
<div class="container">
<div class="row justify-content-between">
<?php $the_query=new WP_Query( array( 'post_type'=> 'project' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $featured_img_url=get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>
<div class="col-lg-4">
<div class="card mb-2">
<img class="card-img-top" src="<?php echo $featured_img_url ?>" alt="">
<div class="card-body">
<h4 class="card-title"><?php the_title(); ?></h4>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="solid-btn">View</a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p>
<?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
</div>
</div> <!-- .container -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment