I want to make seach image clickable


#1

I add this line of code(<?php the_post_thumbnail(); ?>) to show image of product in search result but now i want to make it clickable …how ?


#2

You have to wrap the image with the page URL. Something like below:

if ( has_post_thumbnail() ) {
	$url = get_permalink();
	echo '<a href="'.$url.'">';
	the_post_thumbnail();
	echo '</a>';
}

#3

<?php esc_html_e( 'Not so happy with results? Search for a new keyword ', 'mk_framework' ); ?>

<?php Mk_SVG_Icons::get_svg_icon_by_class_name(true,'mk-icon-search',16); ?> <?php if ( have_posts() ): while ( have_posts() ) : the_post(); $post_type = get_post_type(); ?>
			<article class="search-result-item">
				<h4 class="the-title"><a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_title(); ?></a></h4>
				<?php the_post_thumbnail(); ?>

				<div class="search-loop-meta">
					<span><?php esc_html_e( 'By', 'mk_framework' ); ?> <?php the_author_posts_link(); ?></span>

						<time datetime="<?php the_time('Y-m-d'); ?>">
		
							<?php the_date('', '<time datetime="'.get_the_time().'">' . esc_html__( 'On', 'mk_framework' ) . ' <a href="'.get_month_link( get_the_time( "Y" ), get_the_time( "m" ) ).'">', '</a></time>'); ?>
							</a>
						</time>
					<?php
						echo '<span class="mk-search-cats">';
							switch ($post_type) {
	
								case 'post':
										echo esc_html__( 'In', 'mk_framework' ) . ' '.get_the_category_list( ', ' );
									break;
								case 'portfolio':
										echo esc_html__( 'In', 'mk_framework' ) . ' '.implode(', ', mk_get_custom_tax(get_the_id(), 'portfolio', true));
									break;	
								case 'news':
										echo esc_html__( 'In', 'mk_framework' ) . ' '.implode(', ', mk_get_custom_tax(get_the_id(), 'news', true));
									break;			
							}
						echo '</span>';
					?>
				</div>



				<div class="the-excerpt"><p><?php mk_excerpt_max_charlength(200) ?></p></div>
			</article>
<?php $post_type = ''; endwhile; mk_post_pagination(NULL); wp_reset_query(); endif; ?>

This is the code for search result page , plz tell how i can get the clickable image of whatever product i search in search bar and go to that product


#4

thanks for resolution of issue ,


#5

Thanks for resolution below image i want to show price of that product also