It works on WordPress

The New WP e-Commerce List Products and Images Hack

Advertisements

This post was moved to http://www.wpworking.com/hacks-2/the-new-wp-e-commerce-list-products-and-images-hack/


Well, this code bellow is what I call a “Chewbacca” code, but it works.

I present you the new hack to list products data and images where you want on your theme, if you are working with WP-ecommerce on WordPress.

It was tested on 3.8.5 version, and worked like a charm. If you are using older versions, check the old hack.

Also check WP e-Commerce Product Showroom 2.0.0 on the plugin menu.

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
// if you are note sure about the value of $wp_table_prefix, perform a search for this
// text on your site, the usual value is "wp_" or something
$sql = "select pt.ID, pt.post_title from wp_posts As pt  ";
$sql .= "LEFT JOIN wp_postmeta As mt ON pt.ID=mt.post_id  ";
$sql .= "WHERE pt.post_type = 'wpsc-product' ";
$sql .= "AND pt.post_status = 'publish' ";
$sql .= "GROUP BY mt.post_id ";
$sql .= "ORDER BY pt.post_title ";
$sql .= "LIMIT 3 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
//
$sqlp = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqlp .= "where wm.meta_key='_wpsc_price' and wm.post_id=".$rs[0];
$sqlp .= " GROUP BY wm.post_id";
$qryp = mysql_query($sqlp);
while($rsp = mysql_fetch_array($qryp)):
	$prc = $rsp[0];
endwhile;
//
$sqli = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqli .= "where wm.meta_key='_thumbnail_id' and wm.post_id=".$rs[0];
$sqli .= " GROUP BY wm.post_id";
$qryi = mysql_query($sqli);
while($rsi = mysql_fetch_array($qryi)):
	//
	$sqlt = "select guid from wp_posts where ID=".$rsi[0];
	$qryt = mysql_query($sqlt);
	while($rst = mysql_fetch_array($qryt)):
		$pht = $rst[0];
	endwhile;
endwhile;


$htmlcod .= "<div class='showrpdiv'>\n";
$htmlcod .= "<ul>\n";
$htmlcod .= "<li><a href=".wpsc_product_url($rs[0]).">".$rs[1]."</a><br>";
$htmlcod .= "<a href='".wpsc_product_url($rs[0])."'>";
$htmlcod .= "<img src='".$pht."' style='width:".$tbwid."px'></a>\n";
$htmlcod .= "</li>\n";
$htmlcod .= "<li>".$prc."</li>\n";                   
$htmlcod .= "</ul>\n";
$htmlcod .= "</div>\n";

endwhile;

echo $htmlcod;
Advertisements

Advertisements