Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #15525

    Hello Kriesi team,

    I would like to display a link to the product parent category on the single product page.

    For example:


    Bottom (parent product category)

    - Skirt (child product category)

    - Skirt01 (a single product page)


    When being on the Skirt01 page,

    Right now the breadcrumb looks like this:

    Home ≫ Products ≫ Bottom ≫ Skirt ≫ Skirt01

    How can I do this?

    Thank you very much.

    Jin

    #87850

    Hi Jin,

    I’m not sure if this is doable or not as it uses the avia_breadcrumbs() function and I’m not sure if it can support checking parent products in that way.

    I’ve tagged the topic for another of the support crew who should be able to give a definitive yes or no and assist with that.

    Regards,

    Devin

    #87851

    Hi, Devin

    Thanks for your reply.

    I’m waiting for the result.

    Regards,

    Jin

    #87852

    Hey!

    Have a look at this thread: http://www.kriesi.at/support/topic/breadcrumbs-glitching-illogical-structure

    Best regards,

    Peter

    #87853

    Hi,Dude

    Thanks the above link.

    I’ve tried the below code:

    $prod_cat = array();

    $prod_cat[] = get_the_term_list(get_the_ID(), ‘product_cat’,”,’;',”,”);

    $cat_array = explode(“;”, $prod_cat[0]);

    $parent = $cat_array[count($cat_array) - 1];

    if(count($cat_array) >= 2) {

    $child = $cat_array[count($cat_array) - 2];

    } else {

    $child = $cat_array[0];

    }

    if(count($cat_array) > 0 ) {

    if($parent == $child) {

    $trail_array = $parent;

    } else {

    $trail_array = $parent . ‘ <span class=”sep”>’ . $separator . ‘</span> ‘ . $child;

    }

    $trail[] = $trail_array;

    }

    Do not work correctly It looks like there is no problem.

    Parent and child are displayed order is reversed.

    Product Category↓

    Bottom

    - Skirt

    - Skirt01

    Displayed↓

    Skirt >> Bottom >> Skirt01

    Is there any other way?

    Best regards,

    Jin

    #87854

    Hi Jin,

    I’ve asked Peter to take a look at your code above to see if there is any additional help he can provide.

    Regards,

    Devin

    #87855

    Try following code instead:

    $prod_cat = array();
    $id = (int) get_the_ID();
    $taxonomy = 'product_cat';

    if ( !empty($id) && !empty($taxonomy) )
    {
    $args = array('orderby' => 'term_id', 'order' => 'ASC', 'fields' => 'all');

    $prod_cat = wp_get_object_terms( $id, $taxonomy, $args );
    wp_cache_add($id, $prod_cat, $taxonomy . '_relationships');
    $prod_cat = apply_filters( 'get_the_terms', $prod_cat, $id, $taxonomy );
    }

    if (!empty($prod_cat))
    {
    $trail_array = '';
    $parent_cats = array();

    foreach ($prod_cat as $cat) {
    if(!empty($cat->parent))
    {
    if (!in_array($cat->parent, $parent_cats, false)) $parent_cats[] = (int) $cat->parent;
    }
    else
    {
    if (!in_array(0, $parent_cats, false)) $parent_cats[] = (int) 0;
    }
    }

    $i = 0;
    foreach ($parent_cats as $parent_cat) {
    foreach ($prod_cat as $cat) {
    if ( !empty($cat->name) && isset($cat->parent) && $cat->parent == $parent_cat )
    {
    if ( $i == 0 )
    {
    $trail_array .= '<a href="'. get_term_link( $cat->slug, $taxonomy ) .'">' . $cat->name . '</a>,';
    }
    else
    {
    $trail_array .= ' <span class="sep">' . $separator . '</span> ' . '<a href="'. get_term_link( $cat->slug, $taxonomy ) .'">' . $cat->name . '</a>,';
    }
    }
    }
    $trail_array = (substr($trail_array,-1) == ',') ? substr($trail_array, 0, -1) : $trail_array;
    $i++;
    }
    $trail[] = $trail_array;
    }
    }

    #87857

    Hey!

    I updated the code.

    Regards,

    Peter

    #87858

    Hi, Peter

    That’s work correctly!!

    Thank you very much your support!:)

    Best Regards,

    Jin

    #87859

    Hi!

    I improved the breadcrumb code a bit. It’s more versatile now.

    Best regards,

    Peter

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘How to get parent category in breadcrumbs on the single product page?’ is closed to new replies.