-
-
Save modemlooper/55f98acd5d99dcf56e6ca7cd9571c4cd to your computer and use it in GitHub Desktop.
CPTUI Posts template
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 | |
/** | |
* 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