Viewing 3 replies - 1 through 3 (of 3 total)
  • Roy Ho

    (@splashingpixelscom)

    Take a look at using WP_Query class for that…

    Thread Starter jayseventwo

    (@jayseventwo)

    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>';
    
    	}
    Roy Ho

    (@splashingpixelscom)

    Here are all the instructions you need -> https://codex.www.ads-software.com/Class_Reference/WP_Query

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I want to list categories, sub categories and products’ is closed to new replies.