Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying (but failing) to create 'Best Sellers' and 'New Releases' pages for my website. I'm using WP-Ecommerce 3.8.4 with WP 3.1.3 and I've gotten close but can't seem to get it right. Any help on this would be greatly appreciated...

I've added the following code to wp-ecommerce>wpsc-includes>product-template.php (original code from here):

//Popular products function
function popular_products ( $atts ) {
//Expose the Db to the function
global $wpdb;
//Get the results
$pp = $wpdb -> get_results ( "SELECT prodid, SUM(quantity) FROM {$wpdb->prefix}wpsc_cart_contents GROUP BY prodid ORDER BY quantity DESC LIMIT {$atts['limit']}", ARRAY_A);
//Loop through the results
foreach ( $pp as $item ) {
//Output it
?>
<img alt="<?php echo wpsc_the_product_title ( null, null, $item['prodid'] )?>" src="<?php echo wpsc_the_product_thumbnail ( null, null, $item['prodid'] )?>" />
<?php echo wpsc_the_product_title ( $item['prodid'] )?>
<?php
}
}
add_shortcode ( 'dm_popular', popular_products ); 

//END OF POPULAR PRODUCTS 

I've then added [dm_popular limit=5] to the best sellers page (http://www.iconiccanvasart.co.uk/best-sellers) but as you can see it's not quite working properly:

  1. one product can appear multiple times if it's been ordered in different variations.
  2. it isn't retrieving the Products title properly (all are outputted as 'Best Sellers').
  3. Ditto for the image Alt tags.
  4. I've not added a URL to the products yet as not sure how to at the moment.

Once I've this working I'm hoping to alter slightly and have a 'New Releases' page based on a similar query (so any help on this may help to killing two birds with one stone).

Any help would be greatly appreciated.

ChainsawDR

EDIT: I've since managed to get this all working bar the price and product text - final code can be viewed here: http://getshopped.org/forums/topic/bestselling-products/

share|improve this question
2  
There's a Support Forum at the plugins homepage... –  kaiser Jun 25 '11 at 19:14
    
These two accounts seem to be of one person, would you like them to be merged? –  Rarst Aug 2 '11 at 17:05
    
yes please, I had trouble with the openid so started using my google account now. Thanks buddy –  Dean Rowe Aug 12 '11 at 20:10
add comment

1 Answer

up vote 2 down vote accepted

wpsc_the_product_title is just a wrapper for get_the_title, and it doesn't take any arguments.

Call setup_postdata( $item['prodid'] ) at the start of your foreach loop, and then the function should perform as expected.

share|improve this answer
    
thank you TheDeadMedic - I was calling the wrapper in a few instances. It's still not working perfectly but I think that's to do with the SQL code. I'll work on this and post final code if I get it working. Thanks again ChainsawDR –  Dean Rowe Jun 26 '11 at 12:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.