<?php
/* Template Name: Categorías Zanon */
get_header();
?>

<div class="contenido-zanon">
  <?php
  $marca_slug = 'zanon';

  $args = array(
      'post_type' => 'product',
      'posts_per_page' => -1,
      'tax_query' => array(
          array(
              'taxonomy' => 'marca',
              'field'    => 'slug',
              'terms'    => $marca_slug,
          ),
      ),
  );

  $query = new WP_Query($args);
  $categorias = array();

  if ($query->have_posts()) {
      while ($query->have_posts()) {
          $query->the_post();
          $terms = get_the_terms(get_the_ID(), 'product_cat');
          if ($terms && !is_wp_error($terms)) {
              foreach ($terms as $term) {
                  $categorias[$term->term_id] = $term;
              }
          }
      }
      wp_reset_postdata();
  }

  if (!empty($categorias)) {
      echo '<ul class="categorias-zanon">';
      foreach ($categorias as $cat) {
          echo '<li><a href="' . get_term_link($cat) . '">' . $cat->name . '</a></li>';
      }
      echo '</ul>';
  } else {
      echo '<p>No se encontraron categorías para la marca "ZANON".</p>';
  }
  ?>
</div>

<?php get_footer(); ?>
‘product’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘marca’, ‘field’ => ‘slug’, ‘terms’ => $marca_slug, ), ), ); $query = new WP_Query($args); $categorias = array(); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $terms = get_the_terms(get_the_ID(), ‘product_cat’); if ($terms && !is_wp_error($terms)) { foreach ($terms as $term) { $categorias[$term->term_id] = $term; } } } wp_reset_postdata(); } if (!empty($categorias)) { echo ‘‘; } else { echo ‘

No se encontraron categorías para la marca «ZANON».

‘; } ?>