Advertisement
aitormendez

Desplegable categorias

Aug 24th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. <?php } elseif (is_shop() || is_product_category()) {
  2.  
  3.       // creo un array con nombre de variable para cada categoria:
  4.       // $ropa = get_term_by('slug', 'ropa', 'product_cat');
  5.       // $ropa_array = (array)$ropa;
  6.       // $ropa_array_id = $ropa_array['term_id'];
  7.  
  8.       $cat_productos = get_terms('product_cat', 'hide_empty=0');
  9.         foreach ( $cat_productos as $term ) {
  10.            ${$term->slug} = get_term_by('slug', $term->slug, 'product_cat');
  11.            ${$term->slug.'_array'} = (array)${$term->slug};
  12.            ${$term->slug.'_array_id'} =${$term->slug.'_array'}['term_id'];
  13.       };
  14.  
  15.       // luego genero unos argumentos para cada bloque de nombres que quiero separar
  16.  
  17.       $args = array(
  18.         'taxonomy'     => 'product_cat',
  19.         'orderby'      => 'name',
  20.         'show_count'   => true,
  21.         'pad_counts'   => false,
  22.         'hierarchical' => true,
  23.         'title_li'     => '',
  24.         'hide_empty'   => 0,
  25.         'show_option_all' => 'Ver todo',
  26.         'exclude'    => array( $ropa_array_id, $seda_array_id )
  27.       );
  28.  
  29.       $args_seda = array(
  30.         'taxonomy'     => 'product_cat',
  31.         'orderby'      => 'name',
  32.         'show_count'   => true,
  33.         'pad_counts'   => false,
  34.         'hierarchical' => true,
  35.         'title_li'     => '',
  36.         'hide_empty'   => 0,
  37.         'exclude'    => array( $ediciones_array_id, $objetos_array_id, $ropa_array_id )
  38.       );
  39.  
  40.       $args_ropa = array(
  41.         'taxonomy'     => 'product_cat',
  42.         'orderby'      => 'name',
  43.         'show_count'   => true,
  44.         'pad_counts'   => false,
  45.         'hierarchical' => true,
  46.         'title_li'     => '',
  47.         'hide_empty'   => 0,
  48.         'exclude'    => array( $ediciones_array_id, $objetos_array_id, $seda_array_id )
  49.       );
  50. ?>
  51.       <div class="desplegable-cat">
  52.         <a class="" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
  53.           Categorías
  54.         </a>
  55.         <div class="collapse" id="collapseExample">
  56.           <ul class="catego">
  57.             <?php wp_list_categories( $args ); ?>
  58.             <?php wp_list_categories( $args_seda ); ?>
  59.             <?php wp_list_categories( $args_ropa ); ?>
  60.           </ul>
  61.         </div>
  62.       </div>
  63.     <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement