简体   繁体   English

从此循环中排除类别

[英]Exclude category from this loop

i have this code that print all woocommerce categories and i want to hide a single cateogry from this loop.我有这段代码可以打印所有 woocommerce 类别,我想从这个循环中隐藏一个类别。

<?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();
?>

There are any way to exclude from this list -> image the category "Traslados" ?有什么办法可以从这个列表中排除 ->图像类别“Traslados”?

Thanks in advance提前致谢

You'll need the ID of the category you want to exclude, after that, a simple conditional check before printing out the category.您将需要要排除的类别的 ID,然后在打印类别之前进行简单的条件检查。 Like so:像这样:


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM