Skip to content

Instantly share code, notes, and snippets.

@modemlooper

modemlooper/posts.php Secret

Created Mar 31, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.