Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function services_product_functions(){
- ob_start();
- $parent_cat = get_terms( 'product_cat', array(
- 'hide_empty' => false,
- 'parent' => 0
- ));
- echo '<div class="et_pb_module et_pb_tabs ct-tabs">';
- echo '<ul class="et_pb_tabs_controls clearfix" style="min-height: 35px;">';
- $count=0;
- $active ="et_pb_tab_active";
- foreach($parent_cat as $cat){
- echo '<li class="et_pb_tab_'.$count.' '.$active.'"><a href="#">'.$cat->name.'</a></li>';
- $count++;
- $active = '';
- }
- echo '</ul>';
- echo '<div class="et_pb_all_tabs">';
- $count=0;
- $active ="et_pb_active_content et-pb-active-slide";
- foreach($parent_cat as $cat){
- echo '<div class="et_pb_tab et_pb_tab_'.$count.' clearfix '.$active.'">';
- $count++;
- $active = '';
- $custom_query = new WP_Query( array('post_type' => 'product',
- 'tax_query' => array(
- array (
- 'taxonomy' => 'product_cat',
- 'field' => 'slug',
- 'terms' => $cat->slug,
- )
- ),
- 'posts_per_page' => 7 ) );
- if($custom_query->have_posts()) :
- echo '<div class="ct-services">';
- while ( $custom_query->have_posts() ) : $custom_query->the_post();
- $image_listing = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'services-product-featured-img', true );
- ?>
- <div class="services-product-container">
- <div class="content-container">
- <div class="column img-container">
- <a href="<?php the_permalink(); ?>">
- <?php
- if(has_post_thumbnail()){
- the_post_thumbnail('services-product-featured-img');
- }
- else {
- echo '<img src="/wp-content/uploads/2018/10/placeholder-340x180.png" alt="" />';
- }
- ?>
- </a>
- </div>
- <div class="container-title">
- <h4><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h4>
- <p class="product-category-list"><?php the_category(); ?></p>
- <?php
- echo '<ul class="product-cat">';
- $terms = get_the_terms ( get_the_ID(), 'product_cat' );
- foreach ( $terms as $term ) {
- echo '<li><a href="'.get_term_link( $term ).'">'.$term->name.'</a></li>';
- }
- echo '</ul>';
- ?>
- </div>
- </div>
- </div>
- <?php
- endwhile;
- echo '</div>';
- endif;
- wp_reset_postdata();
- ?>
- <?php
- echo '</div>';
- }
- $content = ob_get_contents();
- ob_clean();
- return $content;
- }
- add_shortcode ( 'services-product' , 'services_product_functions' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement