wordpress“get_terms” - 如何获得子类别?

时间:2017-12-06 18:05:55

标签: php wordpress woocommerce

我有代码,按父类别显示woocommerce类别(类别名称+链接)。但它只显示在woocomerce类别(内部类别),当我点击子类别它的dissapeears。我需要在子类别中显示

我的代码:

<?php
  function tutsplus_product_subcategories($args = array())
  {
      $parentid = get_queried_object_id();
      $args     = array(
          'parent' => $parentid
      );
      $terms    = get_terms('product_cat', $args);
      if ($terms) {
          echo '<ul class="gallery-list">';
          foreach ($terms as $term) {
              echo '<li class="product-category">';
              echo '<h2>';
              echo '<a href="' . esc_url(get_term_link($term)) . '" class="' . $term->slug . '">';
              echo $term->name;
              echo '</a>';
              echo '</h2>';
              echo '</li>';
          }
          echo '</ul>';
      }
  }
  add_action('woocommerce_before_shop_loop', 'tutsplus_product_subcategories', 50);
  function tutsplus_product_cats_css()
  {
      /* register the stylesheet */
      wp_register_style('tutsplus_product_cats_css', plugins_url('style.css', __FILE__));
      /* enqueue the stylsheet */
      wp_enqueue_style('tutsplus_product_cats_css');
  }
  add_action('wp_enqueue_scripts', 'tutsplus_product_cats_css');
?>

0 个答案:

没有答案