Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <div class="slider">
  2.  
  3. <ul>
  4. <?php
  5. $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
  6. $sticky = get_option('sticky_posts');
  7. $args_cat_only = array (
  8. 'my_cat' => $term->slug,
  9. 'posts_per_page' => -1,
  10. 'post__in' => $sticky,
  11. 'post_type' => MYCPT_POST_TYPE,
  12. 'post_status' => 'publish',
  13. 'orderby' => 'rand',
  14. );
  15. $cat_only_query = new WP_Query( $args_cat_only );
  16.  
  17. if ( $cat_only_query->have_posts() ) {
  18. while ( $cat_only_query->have_posts() ) {
  19. $cat_only_query->the_post(); ?>
  20.  
  21. <li>
  22. // items from category only
  23. </li>
  24.  
  25. <?php } wp_reset_postdata();
  26.  
  27. if( count($cat_only_query->posts) <= 4 ) {
  28.  
  29. $args_all_cats = array ( //Args to pull from all categories
  30. 'orderby' => 'rand',
  31. 'posts_per_page' => -1,
  32. //'my_cat' => $term->slug,
  33. 'post__in' => $sticky,
  34. 'post_type' => MYCPT_POST_TYPE,
  35. 'post_status' => 'publish'
  36. );
  37.  
  38. $cat_query_all = new WP_Query( $args_all_cats );
  39.  
  40. if( $cat_query_all->have_posts() ) {
  41. while( $cat_query_all->have_posts() ) {
  42. $cat_query_all->the_post(); ?>
  43.  
  44. <li>
  45. // items from ALL categories
  46. </li>
  47.  
  48. <?php } wp_reset_postdata();
  49. }
  50. }
  51. }
  52. ?>
  53. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement