Custom posts
// FUNCTIONS.PHP
// create shortcode to list all clothes which come in blue
add_shortcode( 'list-posts', 'rmcc_post_listing_shortcode1' );
function rmcc_post_listing_shortcode1( $atts ) {
ob_start();
// define attributes and their defaults
extract( shortcode_atts( array (
'type' => 'post',
'order' => 'DESC',
'orderby' => 'date',
'posts' => '',
'category' => '',
'paged' => ''
), $atts ) );
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$temp = $wp_query; // re-sets query
$wp_query = null; // re-sets query
// define query parameters based on attributes
$args = array(
'post_type' => $type,
'order' => $order,
'orderby' => $orderby,
'posts_per_page' => $posts,
'category_name' => $category,
'paged' => $paged
);
$wp_query = new WP_Query( $args );
//$query = new WP_Query( $options );
// run the loop based on the query
if ( $wp_query->have_posts() ) {
$obj = get_post_type_object( $type );
$template = $obj->labels->name;
$tmpl = $template . '-tmpl.php';
//echo $tmpl;
include $tmpl;
$myvariable = ob_get_clean();
return $myvariable;
}
}
// posts-tmpl.php
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<article class="testimonials-article gray-full-width">
<?php echo get_the_post_thumbnail( $post_id, 'full', array( 'class' => 'alignleft' ) ); ?>
<blockquote>
<?php the_content();?>
</blockquote>
<p><i><?php the_title();?></i></p>
</article>
<?php endwhile;
wp_reset_postdata(); ?>