Skip to content

Instantly share code, notes, and snippets.

@Aeonexe
Created April 3, 2018 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aeonexe/7f96ff080b747b6a9278f40f604d96f0 to your computer and use it in GitHub Desktop.
Save Aeonexe/7f96ff080b747b6a9278f40f604d96f0 to your computer and use it in GitHub Desktop.
Woocommerce Muestra el archivo por categorías, cata categoría linkea a su categoría hija hasta llegar al producto.
<?php
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid,
'childless' => false,
'hide_empty' => false,
'orderby' => 'count',
//'child_of' => 15,
//'fields' => 'all',
);
$terms = get_terms( 'product_cat', $args );
//print_r($parentid);
//print_r($terms);
if ( $terms ) {
foreach ( $terms as $term ) {
?>
<p>
<a href="<?php echo get_term_link( $term ); ?>" class="<?php echo $term->slug; ?>">
<?php echo $term->name; ?> <?php echo $term->count; ?>
</a>
</p>
<?php $term_name = $term->name; ?>
<?php if( $term->count != 0 ) : ?>
<?php $args = array(
'post_type' => 'product',
'category_name' => $term_name,
);
$wp_query = new WP_Query( $args ); ?>
<?php endif; ?>
<?php
}
}
$with_children = get_term_children( $parentid, 'product_cat' );
if( ! $with_children ) :
if ( have_posts() ) : while( have_posts() ) : the_post();
//the_title();
$tags = get_the_terms( $post->ID, 'product_tag' );
foreach ( $tags as $tag ) {
?>
<a href="<?php the_permalink(); ?>">
<?php echo $tag->name; ?>
</a>
<?php
}
//print_r($tags);
echo '<br>';
endwhile; else : if( !is_shop() ) : echo 'aún no hay productos'; endif; endif;
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment