Guest User

Post articles sc

a guest
Aug 20th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1.  
  2. /*-----------------------------------------------------------------------------------*/
  3. /* Post articles
  4. /*-----------------------------------------------------------------------------------*/
  5. if (!function_exists('kleo_articles')) :
  6. function kleo_articles( $atts, $content = null )
  7. {
  8. extract(shortcode_atts(array(
  9. 'cat' => 'all',
  10. 'limit' => 9,
  11. 'post_types' => 'post',
  12. 'post_formats' => 'all'
  13. ), $atts));
  14.  
  15. $args = array();
  16. if ((int)$cat != 0)
  17. {
  18. $args['cat'] = $cat;
  19. }
  20. if ((int)$limit != 0)
  21. {
  22. $args['posts_per_page'] = $limit;
  23. }
  24.  
  25. $args['post_type'] = explode(',', $post_types);
  26.  
  27. $formats = explode(',',$post_formats);
  28. if (is_array($formats) && !in_array('all', $formats))
  29. {
  30. foreach($formats as $format)
  31. {
  32. $terms_query[] = 'post-format-'.$format;
  33. }
  34. $args['tax_query'] = array(
  35. array(
  36. 'taxonomy' => 'post_format',
  37. 'field' => 'slug',
  38. 'terms' => $terms_query
  39. )
  40. );
  41. }
  42.  
  43. $latestPosts = new WP_Query(apply_filters('kleo_articles_args',$args));
  44.  
  45. ob_start();
  46. if ( $latestPosts->have_posts() ) :
  47.  
  48. /* Start the Loop */
  49. while ( $latestPosts->have_posts() ) : $latestPosts->the_post();
  50.  
  51. get_template_part( 'content', get_post_format() );
  52.  
  53. endwhile;
  54.  
  55. wp_reset_postdata();
  56.  
  57. else :
  58. get_template_part( 'content', 'none' );
  59. endif;
  60.  
  61. $output = ob_get_clean();
  62.  
  63. return $output;
  64. }
  65. add_shortcode('kleo_articles', 'kleo_articles');
  66. endif;
Advertisement
Add Comment
Please, Sign In to add comment