wordpress 設計theme 時需要在首頁取得wp ecommerce 的最新產品資料,可以用以下方法,輸出圖片,和title,網上找沒什麼資料,只好自己在widget 改一下那來用
[php]
global $wpdb;
$args = wp_parse_args( (array)$args, array( ‘number’ => 5 ) );
$number = 3;
$image = true;
$width = 150;
$height = 150;
$latest_products = get_posts( array(
‘post_type’ => ‘wpsc-product’,
‘numberposts’ => $number,
‘orderby’ => ‘post_date’,
‘post_parent’ => 0,
‘post_status’ => ‘publish’,
‘order’ => ‘DESC’
) );
$output = ”;
if ( count( $latest_products ) > 0 ) {
$output .= ‘
- ‘;
- ‘;
// Thumbnails, if required
if ($image) {
$output .= ‘‘;
$output .= ‘ID, $width, $height ) . ‘” title=”‘ . $latest_product->post_title . ‘” alt=”‘ . $latest_product->post_title . ‘” />’;
else
$output .=’‘;$output .= ‘‘;
$output .= ‘‘;
}
// Link
$output .= ‘ 發佈於 分類 php, wordpress
foreach ( $latest_products as $latest_product ) {
$output .= ‘