Single product view
-
Hello!
What function/s should I use to display product information (title, image, description, price etc.) when creating single product view page – mp_product.php.
-
Hi @salvisb
The functions you need to use are documented in the following file:
/marketpress/marketpress-includes/template-functions.phpIt’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: http://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.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 π
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 – http://screencast.com/t/cA72q2r5j0.Any ideas?
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.Thanks, Jack.
I will try it out and let you know how it did..It doesn’t work. The thing what it does – it just echo’s string of “Array”.
Screenshot: http://screencast.com/t/HkZLG5b57GTHi 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.Screenshot: http://screencast.com/t/VbgURAGexuJD
Closer, but still with mistakes (outputs unnecessary information) and without styling. ;/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.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:
http://screencast.com/t/zioU6cym3RxAfter adding that code:
http://screencast.com/t/0qOLm8nl4Hi 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,
DavidMJust 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
AshHi 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,
SalvisHi 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
The topic ‘Single product view’ is closed to new replies.