Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用thumbnai图像中的锚定标记重定向到wordpress中的类别页面_Php_Wordpress - Fatal编程技术网

Php 使用thumbnai图像中的锚定标记重定向到wordpress中的类别页面

Php 使用thumbnai图像中的锚定标记重定向到wordpress中的类别页面,php,wordpress,Php,Wordpress,我使用了一个logo滑块并调用了theu post\u thumbnai()函数来显示图像。缩略图来自不同的类别。现在,当我保留anchor标记并使用permalink时,它会在single.php页面中链接到我。 我想重定向到具有相同类别的产品页面的链接。 我使用了以下代码 <?php $categories=get_the_category(); $output=''; if($categories){ foreach ($categories as $category ) { $

我使用了一个logo滑块并调用了
theu post\u thumbnai()
函数来显示图像。缩略图来自不同的类别。现在,当我保留anchor标记并使用permalink时,它会在
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;
   }?>