Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. <?php
  2.  
  3. namespace SeventhQueen\Typer;
  4.  
  5. global $post;
  6. $args = [
  7. 'post__not_in' => [ $post->ID ],
  8. 'post_type' => 'post',
  9. 'showposts' => 8,
  10. 'post_status ' => 'publish',
  11. 'orderby' => 'rand',
  12. 'order' => 'ASC'
  13. ];
  14.  
  15. if ( is_singular( 'post' ) ) {
  16. $categories = get_the_category( $post->ID );
  17.  
  18. if ( ! empty( $categories ) ) {
  19. $category_ids = [];
  20. foreach ( $categories as $rcat ) {
  21. $category_ids[] = $rcat->term_id;
  22. }
  23.  
  24. $args['category__in'] = $category_ids;
  25. }
  26. } else {
  27. $categories = get_object_taxonomies( $post );
  28.  
  29. if ( ! empty( $categories ) ) {
  30. foreach ( $categories as $tax ) {
  31. $terms = wp_get_object_terms( $post->ID, $tax, [ 'fields' => 'ids' ] );
  32.  
  33. $args['tax_query'][] = [
  34. 'taxonomy' => $tax,
  35. 'field' => 'id',
  36. 'terms' => $terms
  37. ];
  38. }
  39. }
  40. }
  41.  
  42. if ( ! $categories ) {
  43. return;
  44. }
  45.  
  46. $the_query = new \WP_Query( $args );
  47.  
  48. ?>
  49.  
  50. <?php if ( $the_query->have_posts() ) : ?>
  51.  
  52. <?php \TYPER_Assets::instance()->enqueue_swiper(); ?>
  53.  
  54. <div class="svq-media-slider svq-post-related">
  55. <div class="heading-title">
  56. <div class="heading-title-content">
  57. <h2 class="heading-title-text">
  58. <?php esc_html_e( 'Related articles', 'typer' ) ?>
  59. </h2>
  60. </div>
  61. </div>
  62.  
  63. <div class="svq-slider-articles svq-article--list-card">
  64. <div class="swiper-wrapper">
  65. <?php
  66.  
  67. $media_width = typer()->get_option( 'blog_related_thumbnail' );
  68. $media_size = $media_width === 'normal' ? 'typer-img-sm' : 'typer-img-lg';
  69.  
  70. while ( $the_query->have_posts() ) {
  71. $the_query->the_post();
  72.  
  73. if ( $media_width === 'wide' && get_post_format() === 'gallery' ) {
  74. $media_size = 'auto';
  75. }
  76.  
  77. typer()->set_post_data( 'listing_type', 'masonry' );
  78. typer()->set_post_data( 'media_size', $media_size );
  79. typer()->set_post_data( 'media_width', $media_width );
  80. typer()->set_post_data( 'media_aspect_ratio', $media_width !== 'normal' ? '16-9' : '1-1' );
  81. typer()->set_post_data( 'col_classes', 'swiper-slide' );
  82.  
  83. typer()->get_template_part( 'template-parts/archive/article-box' );
  84. }
  85.  
  86. ?>
  87. </div>
  88.  
  89. <?php if ( $the_query->post_count > 1 ) : ?>
  90. <div class="svq-article-btn">
  91. <a href="#" class="btn btn-light btn-sm button-ripple slide-to--back">
  92. <?php echo typer()->load_icon( 'long-arrow-left', 18 ) ?>
  93. </a>
  94. <a href="#" class="btn btn-light btn-sm button-ripple btn-icon--right slide-to--next">
  95. <?php esc_html_e( 'Next', 'typer' ) ?>
  96. <?php echo typer()->load_icon( 'long-arrow-right', 18 ) ?>
  97. </a>
  98. </div>
  99. <?php endif; ?>
  100.  
  101. </div>
  102. </div>
  103.  
  104. <?php else: ?>
  105.  
  106. <div class="svq-no-related"></div>
  107.  
  108. <?php endif; ?>
  109.  
  110. <?php
  111.  
  112. wp_reset_postdata();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement