Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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 从此循环中排除类别_Php_Wordpress - Fatal编程技术网

Php 从此循环中排除类别

Php 从此循环中排除类别,php,wordpress,Php,Wordpress,我有这个代码可以打印所有woocommerce类别,我想在这个循环中隐藏一个Cateogray <?php $get_featured_cats = array( 'taxonomy' => 'product_cat', 'orderby' => 'name', 'hide_empty' => '0', 'include' => $cat_array, ); $all_categories = get_catego

我有这个代码可以打印所有woocommerce类别,我想在这个循环中隐藏一个Cateogray

<?php
$get_featured_cats = array(
  'taxonomy'     => 'product_cat',
  'orderby'      => 'name',
  'hide_empty'   => '0',
  'include'      => $cat_array,

);

$all_categories = get_categories( $get_featured_cats );
$j = 1;
foreach ($all_categories as $cat) {
  echo '<div class="col-sm-3 wow fadeInUp ">
        <div class="card mb-3" style="">
        <div class="row no-gutters align-items-center">';
  $cat_id   = $cat->term_id;
  $cat_link = get_category_link( $cat_id );

  $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); // Get Category Thumbnail
  $image = wp_get_attachment_url( $thumbnail_id );
  if ( $image ) {
    echo '<div class="col-md-4 mini-card-categorie-citta" style="background-image: url(' . $image . ')"></div>';
  }
  echo '<div class="col-md-8">
        <div class="card-body">
        <a href="'. $cat_link .'"><h6 class="card-title" style="margin-bottom: 0px;">';
  echo $cat->name; // Get Category Name
  echo '</h6></a>
        </div>
        </div>
      </div>
      </div>
      </div>';
  $j++;
}
// Reset Post Data
wp_reset_query();
?>

您需要要排除的类别的ID,然后在打印类别之前进行简单的条件检查。像这样:


    $imageCategoryId = 12 //Or whatever your image category id is
    foreach ($all_categories as $cat) {
        if($cat->term_id !== $imageCategoryId) {
            //Display category
        }
    }


一个基本条件似乎足以解决你的问题。你试过什么?显示您的最佳尝试。在循环之前取消设置$all_类别中“Traslados”的数组键