add the category title to products in the GK Products Galler

Modern e-commerce WordPress theme to build successful online store with WooCommerce support.
GK User
Wed Oct 30, 2013 12:59 am
I am trying to add the category title to products in the GK Products Gallery widget.
I have found the file to edit: widgets.product_gallery.php However, i am struggling with the code to echo category title? can anyone please help?

i have add this code that is not correct:
Code: Select all
//  am trying to add category title here
               echo '<h4><a href="'.$art_url.'" title="'.strip_tags($single_cat_title).'">'.$single_cat_title.'</a></h4>';



Code: Select all
   // if there is image
            if($art_image !== FALSE) {   
               // URL
               $art_url = get_permalink($art_ID);      
               // output
               echo '<div class="gk-image">';
               // image
               echo '<a href="'.$art_url.'" title="'.strip_tags($art_title).'">';
               echo '<img src="'.$art_image.'" alt="'.strip_tags($art_title).'" />';
               echo '</a>';
               // header
               echo '<h4><a href="'.$art_url.'" title="'.strip_tags($art_title).'">'.$art_title.'</a></h4>';
               
               //  am trying to add category title here
               echo '<h4><a href="'.$art_url.'" title="'.strip_tags($single_cat_title).'">'.$single_cat_title.'</a></h4>';
               
            
               
               echo '<div class="gk-price">'.$price.'</div>';
               echo '<div class="gk-add-to-cart"><a href="'.$art_url.'" title="'.strip_tags($art_title).'" class="addtocart-button">'.__('View Artwork', GKTPLNAME).'</a></div>';
               echo '</div>';
               // increase the amount
               $amount++;
            }
         }
      }      }
      }



regards
Michael
User avatar
Junior Boarder

GK User
Wed Oct 30, 2013 8:49 am
Hi, i used this code somewhere to display link to category on single product page, it should be helpfull:
Code: Select all
<?php
      $size = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
      echo $product->get_categories( ', ', '<span class="wc_category">' . _n( 'Back to:', 'Categories:', $size, 'woocommerce' ) . ' ', '.</span>' );
   ?>


but if it doesn't help, you should ask WooCommerce support, because it's connected only with their plugin.
User avatar
Moderator

GK User
Wed Oct 30, 2013 10:52 am
Hi Piotr,

I had already tried that code you sent. I posted this to you as this code is Gavick's code.. "GK Product Gallery Widget class" (GK Products Gallery) not woo commerce.

i have also tried inseting $the_title and product_cat below in attempt to echo the category title/label ?

Code: Select all
 echo '<h4><a href="'.$art_url.'" title="'.strip_tags($the_title).'">'.$the_title.'</a></h4>';


the product title as an example on the GK Product Gallery Widget class looks like this:

Code: Select all
 echo '<h4><a href="'.$art_url.'" title="'.strip_tags($art_title).'">'.$art_title.'</a></h4>';


Regards,
Michael.
User avatar
Junior Boarder

GK User
Wed Oct 30, 2013 3:29 pm
Try this code to display category name:
Code: Select all
$terms = get_the_terms( $art_ID, 'product_cat' );
$single_cat = array_shift( $terms );
echo '<h4>' . $single_cat->name . '</h4>';
User avatar
Moderator

GK User
Mon Nov 04, 2013 5:20 am
Thanks - This worked
User avatar
Junior Boarder


cron