WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
I want to list categories, sub categories and products (4 posts)

  1. jayseventwo
    Member
    Posted 1 year ago #

    Hi guys, i need to be able to output - in a list style - a category, then its sub-category and then all the products listed in that sub-category.

    I don't want any images etc, just a list <li> style with each product linked to its page.

    Any ideas?

    Cheers
    http://wordpress.org/extend/plugins/woocommerce/

  2. Roy
    Member
    Posted 1 year ago #

    Take a look at using WP_Query class for that...

  3. jayseventwo
    Member
    Posted 1 year ago #

    Would you be able to supply a quick example?

    Thanks.

    Some code i came across which outputs categories but not products:

    function get_product_terms( $term_id ) {
    
    		$html = '';
    
    		$args = array( 'hide_empty' => 0, 'parent' => $term_id );
    
    		$terms = get_terms('product_cat', $args);
    
    		foreach ($terms as $term) {
    
    			$html .= '<li';
    
    			if( $term_id == 0 ) {
    
    				$html .= ' class="top_li"';
    
    			}
    
    			$html .= '><a href="'.get_term_link($term->slug, 'product_cat').'">' . $term->name . '</a>';	
    
    			if( $list = get_product_terms( $term->term_id )) {
    
    				$html .= '<ul class="second_level">'.$list.'</ul>';
    
    			}
    
    			$html .= '</li>';
    
    		}
    
    		return $html;
    
    	}
    
    	if( $list = get_product_terms( 0 )) {
    
    		echo '<ul id="top_ul">'.$list.'</ul>';
    
    	}
  4. Roy
    Member
    Posted 1 year ago #

    Here are all the instructions you need -> http://codex.wordpress.org/Class_Reference/WP_Query

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.