使用Thumbnai图像中的锚标记重定向到WordPress中的类别页面


use anchor tag in thumbnai image to redirect to category page in wordpress

我使用了徽标滑块并调用the_post_thumbnai()函数来显示图像。缩略图来自不同的类别。现在,当我保留锚标签并使用永久链接时,它会single.php页面中链接到我。我想将链接重定向到具有相同类别的产品页面。我使用了以下代码,

<?php 
$categories=get_the_category();
$output='';
 if($categories){
foreach ($categories as $category ) {
$output.='<a  href="'.get_category_link($category->term_id).'?slug='.$category->slug.'">'
.$category->cat_name.'</a>';
 }
  echo $output;
 }?>
<?php 
    $categories=get_the_category();
    $output='';
   if($categories){
      foreach ($categories as $category ) {
          $args = array(
                        'category'         => $category->term_id    ,
                        'post_type'        => 'post',
                        'post_status'      => 'publish',
         ); 
          $posts_array = get_posts( $args );
           foreach ( $posts_array as $post ) :  
              setup_postdata( $post );
              $output.='<a  href="'.get_permalink();.'">'
             .$category->cat_name.'</a>';
          endforeach; 
        wp_reset_postdata();
      }
      echo $output;
   }?>