2012-11-13 57 views
0

我這裏的代碼,但我怎麼能與特定類別如何讓類別以顯示WP電子商務的所有產品

像其中有「1」

ID爲「電子」設置

這裏是代碼

<?php 
// get the product categories 
$product_categories = wp_get_object_terms(wpsc_the_product_id(), 'wpsc_product_category', array('fields' => 'ids')); 
// arguments 
$args = array(
'post_type' => 'wpsc-product', 
'post_status' => 'publish', 
'posts_per_page' => -1, 
'orderby' => 'rand', 
'tax_query' => array(
    array(
     'taxonomy' => 'wpsc_product_category', 
     'field' => 'id', 
     'terms' => $product_categories 
    ) 
) 
); 
$related_products = new WP_Query($args); 
// loop over query 
if ($related_products->have_posts()) : 
echo '<ul>'; 
while ($related_products->have_posts()) : $related_products->the_post(); 
?> 
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> 
<?php 
endwhile; 
echo '</ul>'; 
endif; 
// Reset Post Data 
wp_reset_postdata(); 
?> 

它顯示產品在該網頁上,我需要根據我把什麼類別中顯示的產品,這樣它會從頁面的產品不同

+0

請幫忙:http://www.subharanjan.in/category-wise-products-display-in-wp-e-commerce/ – GBD

回答

0

個選擇職位僅從這一類,像這樣一個在循環代碼:

query_posts(array('category_name' => 'Electronic', 'showposts' => '1')); 
if (have_posts()): while (have_posts()) : the_post(); 
... 

修訂 例子:

<?php 
query_posts(array('category_name' => 'Electronic', 
        'showposts'  => '1')); // Replace '1' with posts quantity per page 
echo '<ul>'; 
if (have_posts()): while (have_posts()) : the_post(); 
    ?> 

<li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> 

<?php 
endwhile; 
    echo '</ul>'; 
endif; 
// Reset Post Data 
wp_reset_postdata(); 
?> 

我想最後的代碼可以代替問題的腳本。不確定,但是,因爲無法測試它。

注意:當然,您必須創建類別並將職位分配給該類別,或使用現有類別:wpsc_product_category

+0

你好,我應該在哪裏放這個代碼,我是新的 –

+0

讓我嘗試用一​​個例子來更新答案。 –

相關問題