Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------------------------------------------*/
- /* Post articles
- /*-----------------------------------------------------------------------------------*/
- if (!function_exists('kleo_articles')) :
- function kleo_articles( $atts, $content = null )
- {
- extract(shortcode_atts(array(
- 'cat' => 'all',
- 'limit' => 9,
- 'post_types' => 'post',
- 'post_formats' => 'all'
- ), $atts));
- $args = array();
- if ((int)$cat != 0)
- {
- $args['cat'] = $cat;
- }
- if ((int)$limit != 0)
- {
- $args['posts_per_page'] = $limit;
- }
- $args['post_type'] = explode(',', $post_types);
- $formats = explode(',',$post_formats);
- if (is_array($formats) && !in_array('all', $formats))
- {
- foreach($formats as $format)
- {
- $terms_query[] = 'post-format-'.$format;
- }
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'post_format',
- 'field' => 'slug',
- 'terms' => $terms_query
- )
- );
- }
- $latestPosts = new WP_Query(apply_filters('kleo_articles_args',$args));
- ob_start();
- if ( $latestPosts->have_posts() ) :
- /* Start the Loop */
- while ( $latestPosts->have_posts() ) : $latestPosts->the_post();
- get_template_part( 'content', get_post_format() );
- endwhile;
- wp_reset_postdata();
- else :
- get_template_part( 'content', 'none' );
- endif;
- $output = ob_get_clean();
- return $output;
- }
- add_shortcode('kleo_articles', 'kleo_articles');
- endif;
Advertisement
Add Comment
Please, Sign In to add comment