WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using plugin Woocommerce to do shop online.

I have many categories for example shoes, clothes and so on. How can I display the products of specific category?

I see such product loops of on the sample page, but I only want show the products of a specific category in my index.php.

share|improve this question

closed as off-topic by Johannes Pille, birgire, TheDeadMedic, Pieter Goosen, ialocin Sep 5 '14 at 11:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Johannes Pille, birgire, TheDeadMedic, Pieter Goosen, ialocin
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 16 down vote accepted

You need to create a new loop for that. Here's the code I use for displaying products from a specific category on the home page:

<ul class="products">
        $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'shoes', 'orderby' => 'rand' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>


                <li class="product">    

                    <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

                        <?php woocommerce_show_product_sale_flash( $post, $product ); ?>

                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>

                        <h3><?php the_title(); ?></h3>

                        <span class="price"><?php echo $product->get_price_html(); ?></span>                    


                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>


    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
share|improve this answer
thanks Dwaser much. I've done. that code has worked :D – Van Tong Oct 5 '12 at 16:13
@VanTong Then mark this answer as the answer: click the checkmark on the left side. – toscho Oct 7 '12 at 4:37
Hi Dwaser,I want ask more. If in archive page, I want show all new product. and When I choose specific Category It will show product of that category. Example I have 2 category Category A and Category B,When I choose A, it will show product of A, and choose B it will show product of B. Please tell me loops. thanks. – Van Tong Oct 26 '12 at 12:22
hot show message if there is no products? – Muhammad Bilal Feb 5 '14 at 23:42
@dwaser Hi, deos the product_cat argument accept an int category id, ie: 40 instead of 'shoes' ? if not, how to make it accept an int category id ? thanks – Malloc May 6 '14 at 18:15

There is another way:

You can assign the "Shop" page as default home page. Now all the products will displayed to the home page. I mean index.php.

share|improve this answer

Try this

    echo $product->get_categories(
        ', ',
        '<span class="posted_in">' . _n( 'Category:', 'Categories:',
        sizeof( get_the_terms( $post->ID, 'product_cat' ) ),
        'woocommerce' ) . ' ',
share|improve this answer
Can you elaborate on how and why this would solve the OP's problem? – Johannes Pille Sep 17 '13 at 8:38

protected by Community Apr 8 '14 at 18:00

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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