Advertisement
rdusnr

Untitled

Aug 15th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2.  
  3. /* Query args */
  4. $args=array(
  5. 'post__not_in' => array($post->ID),
  6. 'showposts'=> 8,
  7. 'orderby' => 'rand', //random posts
  8. 'order' => 'ASC' //most recent first
  9. );
  10.  
  11. //logic for blog posts
  12. if (is_singular('post')) {
  13.  
  14. //related text
  15. $related_text = esc_html__("Related Articles", "kleo_framework");
  16.  
  17. $categories = get_the_category($post->ID);
  18.  
  19. if (!empty($categories)) {
  20. $category_ids = array();
  21. foreach ($categories as $rcat) {
  22. $category_ids[] = $rcat->term_id;
  23. }
  24.  
  25. $args['category__in'] = $category_ids;
  26. }
  27. }
  28. // logic for custom post types
  29. else {
  30.  
  31. //related text
  32. $related_text = esc_html__("Related", "kleo_framework");
  33.  
  34. global $post;
  35. $categories = get_object_taxonomies($post);
  36.  
  37. if (!empty($categories)) {
  38. foreach( $categories as $tax ) {
  39. $terms = wp_get_object_terms($post->ID, $tax, array('fields' => 'ids'));
  40.  
  41. $args['tax_query'][] = array(
  42. 'taxonomy' => $tax,
  43. 'field' => 'id',
  44. 'terms' => $terms
  45. );
  46. }
  47. }
  48. }
  49.  
  50. /* Remove this line to show related posts even no categories are found */
  51. if (!$categories) { return; }
  52.  
  53. ?>
  54.  
  55. <?php query_posts($args); if ( have_posts() ) : ?>
  56.  
  57. <section class="container-wrap">
  58. <div class="container">
  59. <div class="related-wrap">
  60.  
  61. <div class="hr-title hr-long"><abbr><?php echo $related_text; ?></abbr></div>
  62.  
  63. <div class="kleo-carousel-container dot-carousel">
  64. <div class="kleo-carousel-items kleo-carousel-post" data-min-items="1" data-max-items="6">
  65. <ul class="kleo-carousel">
  66.  
  67. <?php
  68. while ( have_posts() ) : the_post();
  69.  
  70. get_template_part('page-parts/post-content-carousel');
  71.  
  72. endwhile;
  73. ?>
  74.  
  75. </ul>
  76. </div>
  77. <div class="carousel-arrow">
  78. <a class="carousel-prev" href="#"><i class="icon-angle-left"></i></a>
  79. <a class="carousel-next" href="#"><i class="icon-angle-right"></i></a>
  80. </div>
  81. <div class="kleo-carousel-post-pager carousel-pager"></div>
  82. </div><!--end carousel-container-->
  83. </div>
  84. </div>
  85. </section>
  86.  
  87. <?php
  88. endif;
  89.  
  90. // Reset Query
  91. wp_reset_query();
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement