I’m working on a WordPress site and need help making the featured images clickable. Right now I have a custom loop that displays posts with their thumbnails, but when visitors click on the images nothing happens. I want the images to work like links that take people to the full post page.
Here’s my current setup in the template file:
<section class="content-area">
<?php
$query_args = array('numberposts' => 8);
$custom_query = new WP_Query($query_args);
?>
<?php if ($custom_query->have_posts()) { ?>
<?php while ($custom_query->have_posts()) {
$custom_query->the_post(); ?>
<div class="post-item">
<div class="featured-image">
<?php if (has_post_thumbnail()) { ?>
<?php the_post_thumbnail(); ?>
<?php } ?>
</div>
<h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
<div class="post-content">
<?php the_excerpt(); ?>
</div>
</div>
<?php }
} else { ?>
<p>No posts found.</p>
<?php } ?>
<?php wp_reset_postdata(); ?>
</section>
What’s the best way to wrap the thumbnail with a link so it becomes clickable? I tried a few approaches but they didn’t work properly.