Commit 39e1c0da by rajshah

fixed: handle related case study section if no items are selected

parent c2c083a9
......@@ -8,10 +8,11 @@
<?php the_field('description'); ?>
</div>
</div>
<?php if ($portfolios = get_field('related_portfolios')): ?>
<?php
$portfolios = get_field('related_portfolios');
if (is_array($portfolios) && !empty($portfolios)): ?>
<div class="portfolio-carousel owl-carousel owl-theme">
<?php foreach ($portfolios as $portfolio):
// Check if $portfolio is an object or an ID
$post_id = is_object($portfolio) ? $portfolio->ID : $portfolio;
?>
<div class="item">
......@@ -64,7 +65,79 @@
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
else:
$current_post_id = get_the_ID();
$current_post_type = get_post_type($current_post_id);
$taxonomy = ($current_post_type === 'case-study') ? 'case-study-category' : 'portfolio-category';
$terms = get_the_terms($current_post_id, $taxonomy);
if ($terms && !is_wp_error($terms)) {
$term_ids = wp_list_pluck($terms, 'term_id');
$args = array(
'post_type' => $current_post_type,
'posts_per_page' => 6,
'post__not_in' => array($current_post_id),
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $term_ids,
),
),
);
$related_query = new WP_Query($args);
if ($related_query->have_posts()): ?>
<div class="portfolio-carousel owl-carousel owl-theme">
<?php while ($related_query->have_posts()): $related_query->the_post(); ?>
<div class="item">
<div class="recent-card-wrapper">
<a href="<?php the_permalink(); ?>">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
} else {
if ($current_post_type === 'case-study') {
$case_study_fallback_image = get_field('case-study_fallback_featured_image', 'option');
if ($case_study_fallback_image) {
echo '<img src="' . esc_url($case_study_fallback_image) . '" alt="Case Study Placeholder">';
}
}
}
?>
<div class="bottom-text">
<div class="d-flex align-items-center justify-content-between title">
<div class="heading">
<h3><?php the_title(); ?></h3>
</div>
<div class="site-link">
<p>View Site
<!-- SVG here -->
</p>
</div>
</div>
<ul class="list-unstyled d-flex">
<?php
$related_terms = get_the_terms(get_the_ID(), $taxonomy);
if ($related_terms && !is_wp_error($related_terms)) {
foreach ($related_terms as $term) {
echo '<li>#' . esc_html($term->name) . '</li>';
}
}
?>
</ul>
</div>
</a>
</div>
</div>
<?php endwhile; ?>
</div>
<?php
endif;
wp_reset_postdata();
}
endif;
?>
<?php if ($link = get_field('link')) : $link_target = $link['target'] ? $link['target'] : '_self'; ?>
<a href="<?php echo $link['url']; ?>" target="<?php echo esc_attr($link_target); ?>" class="btn my-60 mx-auto d-flex align-items-center start-project btn-start-project-white"
style="width: fit-content;"><?php echo $link['title']; ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment