Files
Landing/wp-content/themes/upstudy/template-parts/related-posts.php
T

65 lines
3.0 KiB
PHP
Raw Normal View History

2026-04-23 04:33:43 +03:30
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // If this file is called directly, abort.
global $post;
$upstudy_related_posts_to_show = '4';
$upstudy_related_posts_terms = get_the_terms( $post->ID, 'category' );
$upstudy_related_posts_term_ids = array();
if ( $upstudy_related_posts_terms ) :
foreach( $upstudy_related_posts_terms as $term ) :
$upstudy_related_posts_term_ids[] = $term->term_id;
endforeach;
endif;
$upstudy_related_posts_args = array(
'post_type' => 'post',
'posts_per_page' => $upstudy_related_posts_to_show,
'post__not_in' => array( $post->ID ),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $upstudy_related_posts_term_ids,
'operator' => 'IN'
)
)
);
$upstudy_related_posts = new WP_Query( $upstudy_related_posts_args );
if ( $upstudy_related_posts->have_posts() ) :
echo '<div class="upstudy-related-posts-wrapper upstudy-blog-post-archive-style-1">';
$related_products_heading = 'Related Posts';
if ( $related_products_heading ) :
echo '<h3 class="upstudy-related-product-title">' . esc_html( $related_products_heading ) . '</h2>';
endif;
echo '<div class="upstudy-related-product-items tpc-swiper-carousel-activator swiper swiper-container" data-lg-items="3" data-md-items="3" data-sm-items="2" data-xs-items="2">';
echo '<div class="swiper-wrapper">';
while ( $upstudy_related_posts->have_posts() ) : $upstudy_related_posts->the_post();
$upstudy_post_thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'upstudy-post-thumb' );
if ( isset( $upstudy_post_thumb_src ) && ! empty( $upstudy_post_thumb_src ) ) :
$upstudy_post_thumb_url = $upstudy_post_thumb_src[0];
else :
$upstudy_post_thumb_url = '';
endif;
echo '<div class="swiper-slide">';
echo '<div class="upstudy-single-blog" style="background-image: url(' . esc_url( $upstudy_post_thumb_url ) . ')">';
echo '<div class="blog-content">';
echo '<ul class="blog-meta date">';
echo '<li><i class="dt-icon-clock"></i>' . esc_html( get_the_date( get_option( 'date_format' ) ) ) . '</li>';
echo '</ul>';
the_title( '<h4 class="title"><a href="' . esc_url( get_the_permalink() ) . '" class="post-link">', '</a></h4>' );
echo '</div>';
echo '</div>';
echo '</div>';
endwhile;
wp_reset_postdata();
echo '</div>';
echo '</div>';
echo '</div>';
endif;