Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h1>Navigating the products</h1>
- <?php
- //Get a navigation including all products
- ?>
- <ul>
- <?php
- //http://codex.wordpress.org/Template_Tags/wp_list_categories
- $args = array(
- 'show_option_all' => null,
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'style' => 'list',
- 'show_count' => 0,
- 'hide_empty' => 1,
- 'use_desc_for_title' => 1,
- 'child_of' => 0,
- 'feed' => null,
- 'feed_type' => null,
- 'feed_image' => null,
- 'exclude' => null,
- 'exclude_tree' => null,
- 'include' => null,
- 'hierarchical' => true,
- 'title_li' => __( 'Product categories' ),
- 'show_option_none' => __('No product categories available'),
- 'number' => null,
- 'echo' => 1,
- 'depth' => 2,
- 'current_category' => 0,
- 'pad_counts' => 0,
- 'taxonomy' => 'product_category',
- //'walker' => 'Walker_Category'
- 'walker' => new walker_taxonomy_term_posts()
- );
- class walker_taxonomy_term_posts extends Walker_Category {
- function start_el(&$output, $category, $depth, $args) {
- $this->category = $category;
- parent::start_el($output, $category, $depth, $args);
- }
- function end_el(&$output, $page, $depth, $args) {
- if ( 'list' != $args['style'] )
- return;
- //echo $this->category->term_id . ',';
- echo '<pre>';
- print_r($this);
- echo '</pre>';
- $posts = new WP_Query(
- array(
- 'post_type' => 'products',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_category',
- 'field' => 'id',
- 'terms' => $this->category->term_id
- )
- ),
- 'numberposts' => 3
- )
- );
- if( !empty( $posts ) ) {
- $posts_list = '<ul>';
- while ( $posts->have_posts() ) : $posts->the_post();
- $posts_list .= '<li><a href="' . get_permalink( $post->ID ) . '">'.get_the_title( $post->ID ).'</a></li>';
- endwhile;
- wp_reset_query();
- $posts_list .= '</ul>';
- }else{
- $posts_list = '';
- }
- $output .= "{$posts_list}</li>\n";
- }
- }
- wp_list_categories($args);
- wp_reset_query();
- ?>
- </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement