Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //current page taxonomy name and info
- ----------------
- $termss = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );echo $termss->name;
- // query for only parent category info with ACF category metafield
- ---------------------------
- $args = array( 'hide_empty=0' );
- $terms = get_terms( 'product_cat', array( 'parent' => 0 ),$args );
- if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
- foreach ( $terms as $term ) {
- $category_name = $term->name;
- $category_description = $term->description;
- $category_link = esc_url( get_term_link( $term ) );
- $category_banner = get_field( "category_banner", $term );
- //content
- echo '<a href="'.$category_link.'">'.$category_name.'</a>';
- }
- }
- // example for child taxonomy
- ------------------------------------
- <?php
- $term_id = 10;
- $taxonomy_name = 'products';
- $termchildren = get_term_children( $term_id, $taxonomy_name );
- echo '<ul>';
- foreach ( $termchildren as $child ) {
- $term = get_term_by( 'id', $child, $taxonomy_name );
- echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
- }
- echo '</ul>';
- ?>
- // category query example this is for taxonomy.php or taxonomy-taxname.php
- -------------------------------------------------------------------------------
- <?php
- $termss = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); // to get current category
- $terms = get_terms( 'product_cat', $termss );
- if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
- foreach ( $terms as $term ) {
- $category_name = $term->name;
- $category_description = $term->description;
- $category_link = esc_url( get_term_link( $term ) );
- $category_banner = get_field( "category_banner", $term );
- $category_page_logo = get_field( "category_page_logo", $term );
- $category_image = get_field( "category_image", $term );
- $category_color = get_field( "category_color", $term );
- ?>
- <style type="text/css">
- .pdpage_items_cattitle h2 {color:<?php echo $category_color; ?>}
- .pdpage_items_cattitle h2:before{content:"";background: <?php echo $category_color; ?>;}
- .pdpage_items_cattitle h2:after{content:"";background: <?php echo $category_color; ?>;}
- </style>
- <section class="allpage_banner_main_area fix withpditem" style="background:url(<?php echo $category_banner; ?>) no-repeat; background-size: cover;">
- <div class="container">
- <div class="row">
- <div class="col-md-12">
- <div class="allpage_banner_title_wrapper fix">
- <div class="allpage_banner_title_area fix">
- <div class="col-md-5 text-left">
- <div class="allpage_banner_title">
- <h1><?php _e("<!--:en-->Product<!--:--><!--:pb-->Produtos<!--:-->"); ?></h1>
- </div>
- </div>
- <div class="col-md-5 col-md-offset-2 text-right">
- <div class="allpage_banner_breadcumb">
- <p><?php my_breadcrumb(); ?></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </section>
- <section class="pdpage_main_content_area fix">
- <div class="container">
- <div class="row">
- <div class="col-md-12">
- <div class="pdpage_main_content fix">
- <div class="pdpage_titleitem_content fix" style="background-color:<?php echo $category_color; ?>">
- <div class="col-md-3 col-sm-4 margi_left_zero">
- <div class="pdpage_sample_img">
- <img src="<?php echo $category_image;?>" alt="" />
- </div>
- </div>
- <div class="col-md-9 col-sm-8">
- <div class="product_catmain_logo fix">
- <img src="<?php echo $category_page_logo; ?>" alt="" />
- </div>
- <div class="product_catmain_descrip fix">
- <p><?php echo $category_description; ?></p>
- </div>
- </div>
- </div>
- <?php
- // tax query for child tax items
- $term_id = $termss->term_id;
- $taxonomy_name = 'product_cat';
- $termchildren = get_term_children( $term_id, $taxonomy_name );
- foreach ( $termchildren as $child ) {
- $term = get_term_by( 'id', $child, $taxonomy_name );
- $tag_id = $term->term_id;
- ?><div class="pdpage_items_content fix row">
- <div class="col-md-12">
- <div class="pdpage_items_cattitle">
- <h2><?php echo $term->name ; ?></h2>
- </div>
- </div>
- <div class="pdpage_catitems">
- <?php
- $tax_child= new WP_Query(array(
- 'post_type' => 'product-items',
- 'posts_per_page' => -1,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_cat',
- 'field' => 'term_id',
- 'terms' => $tag_id,
- ),
- ),
- ));
- if($tax_child -> have_posts()):
- while($tax_child -> have_posts()): $tax_child -> the_post();?>
- <div class="col-md-6 col-sm-6">
- <div class="pdpage_catitem_single">
- <div class="row">
- <div class="col-md-3 col-sm-3">
- <div class="image_catitem_single" style="background-color:<?php echo $category_color; ?>">
- <img src="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' ); echo $image[0]; ?>" alt="" />
- </div>
- </div>
- <div class="col-md-9 col-sm-9">
- <div class="catitem_single_dtails">
- <div class="catitem_single_title" style="color:<?php echo $category_color; ?>">
- <h2><?php the_title();?> </h2>
- <h4><?php the_field('product_subtitle');?></h4>
- </div>
- <div class="catitem_single_textexcerpt">
- <?php the_content();?>
- </div>
- <div class="catitem_single_popbtnarea">
- <div class="row">
- <div class="col-md-6 col-sm-6">
- <a href="#request_pop" class="btn_request prodtform_pop">solicite uma amostra</a>
- </div>
- <div class="col-md-6 col-sm-6">
- <a href="#morinfo_pop" class="btn_moreinfo prodtform_pop">MAIS INFORMAÇÕES</a>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?php endwhile; ?> <?php endif; wp_reset_query();?>
- </div>
- </div> <?php
- }?>
- <?php
- }
- } ?>
- </div>
- </div>
- </div>
- </div>
- </section>
Advertisement
Add Comment
Please, Sign In to add comment