Skip to content

Instantly share code, notes, and snippets.

@modemlooper
Created March 31, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modemlooper/55f98acd5d99dcf56e6ca7cd9571c4cd to your computer and use it in GitHub Desktop.
Save modemlooper/55f98acd5d99dcf56e6ca7cd9571c4cd to your computer and use it in GitHub Desktop.
CPTUI Posts template
<?php
/**
* Posts shortcode template
*
* @package CPTUIExtended
* @author WebDevStudios
* @license GPLV2
* @since 1.0.0
*/
/*
* This file will have an $attributes array variable available to render various parts of the template. The values in
* the array will be composed of attributes passed in to the shortcode.
*
* You can override it by placing a matching named file in ____.
*
* $args // Arguments to be used with WP_Query. Default: array( 'post_type' => 'post' )
* $attributes // All shortcode attributes from post editor
*/
?>
<div class="post-list-wrapper">
<?php if ( isset( $attributes['title'] ) && '' !== $attributes['title'] ) : ?>
<h3><?php echo esc_attr( $attributes['title'] ); ?></h3>
<?php endif; ?>
<?php
$args['posts_per_page'] = esc_attr( $attributes['amount'] );
$custom_query = new WP_Query( $args );
?>
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<div class="post-list" id="post-<?php the_ID(); ?>">
<?php if ( 'on' === $attributes['featured_image'] ) : ?>
<div class="post-thumb">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
</div>
<?php endif; ?>
<div class="post-content">
<h4 class="post-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h4>
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); // Reset the query. ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment