Viewing 15 replies - 1 through 15 (of 16 total)
  • Mike

    (@michael-copestake)

    Hi @salvisb

    The functions you need to use are documented in the following file:
    /marketpress/marketpress-includes/template-functions.php

    Thread Starter SalvisB

    (@salvisb)

    It’s much easier than I think it would be. ??
    Only a few problems… 1) Don’t know how to display hierarchy of categories where product is placed.
    Screenshot shows what I mean by that: https://screencast.com/t/cA72q2r5j0 (can’t display this section on my mp_product page).
    As far as I know for this section responsible is function
    <?php mp_category_list(); ?> , but it displays nothing. Maybe I just need to pass some parameters in this function?
    2) Another problem is that when I use function <?php mp_product_image(); ?> for image width and height it takes parameters from ‘thumbnail size’ both for ‘single product image settings’ and ‘product list image settings’. When I switch single image settings to display medium or custom size images, nothing happens.

    Mike

    (@michael-copestake)

    Hi @salvisb

    1) Is this not the mp_list_categories functions? Have you tried that?

    2) The mp_product_image function lists this:
    function mp_product_image($echo = true, $context = 'list', $post_id = NULL, $size = NULL)

    The first argument $echo can be true or false. This would normally be true as you’ll see from the default above.
    $context can be: list, single, widget
    $post_id would probably be set to: $post->ID
    $size would be a number(perhaps “array(150,150)”)

    So the final call would be something like:
    mp_product_image(true,single,$post->ID,array(150,150))

    Now please bear in mind, I’m not a coder by any stretch of the imagination, so the above could be completely wrong, please don’t expect too much ??

    Thread Starter SalvisB

    (@salvisb)

    Thanks Mike! Code for displaying product image works great! ?? But I still can’t find right function to allow display categories in the bottom of product.
    Function mp_list_categories displays all the product category tree (as in sitemap), but I need only those categories where the product is placed (as in screenshot which I provided – https://screencast.com/t/cA72q2r5j0.

    Any ideas?

    Jack K

    (@jack-kitterhing)

    Hi there @salvisb

    Greetings, hope your well today.

    This code

    <?php echo wp_get_post_terms( $post->ID, 'product_category' ); ?>

    Should do that for you ??

    Thank you!

    Kind Regards
    Jack.

    Thread Starter SalvisB

    (@salvisb)

    Thanks, Jack.
    I will try it out and let you know how it did..

    Thread Starter SalvisB

    (@salvisb)

    It doesn’t work. The thing what it does – it just echo’s string of “Array”.
    Screenshot: https://screencast.com/t/HkZLG5b57GT

    Jack K

    (@jack-kitterhing)

    Hi there @salvisb,

    I hope you are well today.

    Sorry about that, this should work

    <?php $terms = wp_get_post_terms( $post->ID, 'product_category' ); print_r( $terms ); ?>

    Thank you!

    Kind Regards
    Jack.

    Thread Starter SalvisB

    (@salvisb)

    Screenshot: https://screencast.com/t/VbgURAGexuJD
    Closer, but still with mistakes (outputs unnecessary information) and without styling. ;/

    Jack K

    (@jack-kitterhing)

    Hi there @salvisb,

    I hope you are well today.

    This should work ?? I promise! ??

    <?php
    $terms = wp_get_post_terms( $post->ID, 'product_category' );
    foreach ( $terms as $term  ) :
       echo $term['slug'];
    endforeach;

    Thanks!

    Kind Regards
    Jack.

    Thread Starter SalvisB

    (@salvisb)

    Hi Jack!
    Still nothing. ??
    Now it’s even worse. By adding that line of code it removes everything else excpet information about product and it’s image, but still without category listing.

    Before:
    https://screencast.com/t/zioU6cym3Rx

    After adding that code:
    https://screencast.com/t/0qOLm8nl4

    David

    (@ugotsta)

    Hi SalvisB,

    Could you please add the following onto the end of Jack’s last snippet and let us know how that works for you?

    ?>

    Thanks,
    DavidM

    Plugin Author Ashok

    (@bappidgreat)

    Just chiming in here.

    Would you please try the following code:

    $terms = wp_get_post_terms( $post->ID, 'product_category' );
    foreach($terms as $term) {
    echo $term->name . ', ';
    }

    Please try this and let me know if it improves something.

    Cheers
    Ash

    Thread Starter SalvisB

    (@salvisb)

    Hi Ash!
    By using your code it outputs necessary categories like it should, but there is a few gaps:
    1) Categories are displayed as a plain text, not as a links like it should be.
    2) It misses styling.
    3) Comma ‘,’ are placed after last category aswell, as it shouldn’t be.

    I can correct styling issue, but don’t know how to correct point 1 and 2.

    With best wishes,
    Salvis

    David

    (@ugotsta)

    Hi SalvisB,

    The following should take care of that:

    $html = '<div class="mp_product_categories">';
    $terms = wp_get_post_terms( $post->ID, 'product_category' );
    $termCount = count($terms);
    $i = 0;
    foreach($terms as $term) {
    	$html .= '<a href="'. get_term_link($term) . '">';
    	$html .= $term->name . '</a>';
    	if(++$i !== $termCount) {
    		$html .= ', ';
    	}
    }
    $html .= '</div>';
    echo $html;

    It should also take on the standard MarketPress styling since it adds a div with the mp_product_categories class. Or you could target it with that class to change it.

    Cheers,
    DavidM

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Single product view’ is closed to new replies.