• Resolved junior

    (@epiric)


    Hello there,
    i would kindly ask for someones help. I would like to have on single web shop page all products but divided in categories. So i have layout like

    Category title 1
    products
    Category title 2
    products

    Now i know how to do this with posts in standard word press query but i dont know how to do it here :S . Can some write me custom query to be placed in content-products.php i assume? It can be also even query to display one category separated, even better, so i can do lets say 3 querys separated on one page, so i can style parts separate. Thanks

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter junior

    (@epiric)

    I feel like an idiot now. I just found out how to do it. Topic closed, and if someone needs it here is the code, you can put it on page.php or index.php, or where you need it.

    <ul class="products">
        <?php
            $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; ?>
    
                <h2>Shoes</h2>
    
                    <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>                    
    
                        </a>
    
                        <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
    
                    </li>
    
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
    </ul><!--/.products-->

    Hi epiric, I was wondering if you would be able to explain how you were able to get this to work? I have tried putting this code into the page.php and index.php and nothing seems to have changed. I am not so adept with this level of coding.

    Also, I am not using a woo theme, if that makes any difference. It has caused some issues but they’re slowly being worked through.

    Any help would be very much appreciated!!

    Thanks in advance.

    Thread Starter junior

    (@epiric)

    Hello j.dossis. I tryed to put this on index page and it works. but you have to change => ‘shoes’ in 3d line of code (seen below)
    $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'shoes', 'orderby' => 'rand' );

    and instead of shoes inside of single quotes put any of your category names. if you pasted this code somewhere, and it doesnt show anything, its because you dont have category named “shoes”.. I for example have lets say cookies. so i put that in that line of code…

    I only installed clean woo plugin and thats it..no themes..

    See if that helps ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple categories separated on same page’ is closed to new replies.