?> <div id="default_products_page_container" class="wrap wpsc_container"> <?php wpsc_output_breadcrumbs(); ?> <?php do_action('wpsc_top_of_products_page'); // Plugin hook for adding things to the top of the products page, like the live search ?> <?php if (wpsc_display_categories()) { ?> <?php if (wpsc_category_grid_view()) { ?> <div class="wpsc_categories wpsc_category_grid group"> <?php wpsc_start_category_query(array('category_group' => get_option('wpsc_default_category'), 'show_thumbnails' => 1)); ?> <a href="<?php wpsc_print_category_url(); ?> " class="wpsc_category_grid_item <?php wpsc_print_category_classes_section(); ?> " title="<?php wpsc_print_category_name(); ?> ">
/** * wpsc category loop function * This function recursively loops through the categories to display the category tree. * This function also generates a tree of categories at the same time * WARNING: as this function is recursive, be careful what you do with it. * @param array the category query * @param string the category html * @param array the category array branch, is an internal value, leave it alone. * @return string - the finished category html */ function wpsc_display_category_loop($query, $category_html, &$category_branch = null) { static $category_count_data = array(); // the array tree is stored in this if (isset($query['parent_category_id'])) { $category_id = absint($query['parent_category_id']); } else { $category_id = 0; } $category_data = get_terms('wpsc_product_category', 'hide_empty=0&parent=' . $category_id, OBJECT, 'display'); $output = ''; // if the category branch is identical to null, make it a reference to $category_count_data if ($category_branch === null) { $category_branch =& $category_count_data; } $allowed_tags = array('a' => array('href' => array(), 'title' => array()), 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), 'code' => array(), 'em' => array(), 'strong' => array(), 'b' => array()); $allowedtags = apply_filters('wpsc_category_description_allowed_tags', $allowed_tags); foreach ((array) $category_data as $category_row) { // modifys the query for the next round $modified_query = $query; $modified_query['parent_category_id'] = $category_row->term_id; // gets the count of products associated with this category $category_count = $category_row->count; // Sticks the category description in $category_description = ''; if ($category_row->description != '' && !empty($query['description_container'])) { $start_element = $query['description_container']['start_element']; $end_element = $query['description_container']['end_element']; $category_description = $start_element . wpautop(wptexturize(wp_kses($category_row->description, $allowedtags))) . $end_element; } // Creates the list of classes on the category item $category_classes = wpsc_print_category_classes((array) $category_row, false); // Set the variables for this category $category_branch[$category_row->term_id]['children'] = array(); $category_branch[$category_row->term_id]['count'] = (int) $category_count; // Recurse into the next level of categories $sub_categories = wpsc_display_category_loop($modified_query, $category_html, $category_branch[$category_row->term_id]['children']); // grab the product count from the subcategories foreach ((array) $category_branch[$category_row->term_id]['children'] as $child_category) { $category_branch[$category_row->term_id]['count'] += (int) $child_category['count']; } // stick the category count array together here // this must run after the subcategories and the count of products belonging to them has been obtained $category_count = $category_branch[$category_row->term_id]['count']; $start_element = ''; $end_element = ''; if (isset($query['products_count']['start_element'])) { $start_element = $query['products_count']['start_element']; } if (isset($query['products_count']['end_element'])) { $end_element = $query['products_count']['end_element']; } $category_count_html = $start_element . $category_count . $end_element; if (isset($query['subcategory_container']) && !empty($sub_categories)) { $start_element = $query['subcategory_container']['start_element']; $end_element = $query['subcategory_container']['end_element']; $sub_categories = $start_element . $sub_categories . $end_element; } // get the category images $category_image = wpsc_place_category_image($category_row->term_id, $modified_query); if (empty($query['image_size']['width'])) { if (!wpsc_category_grid_view()) { $width = wpsc_get_categorymeta($category_row->term_id, 'image_width'); } if (empty($width)) { $width = get_option('category_image_width'); } } else { $width = $query['image_size']['width']; } if (empty($query['image_size']['height'])) { if (!wpsc_category_grid_view()) { $height = wpsc_get_categorymeta($category_row->term_id, 'image_height'); } if (empty($height)) { $height = get_option('category_image_height'); } } else { $height = $query['image_size']['height']; } $category_image = wpsc_get_categorymeta($category_row->term_id, 'image'); $category_image_html = ''; if ($query['show_thumbnails'] == 1) { if (!empty($category_image) && is_file(WPSC_CATEGORY_DIR . $category_image)) { $category_image_html = "<img src='" . WPSC_CATEGORY_URL . "{$category_image}' alt='{$category_row->name}' title='{$category_row->name}' style='width: {$width}px; height: {$height}px;' class='wpsc_category_image' />"; } elseif (isset($query['show_name']) && 1 == $query['show_name']) { $category_image_html .= "<span class='wpsc_category_image item_no_image ' style='width: {$width}px; height: {$height}px;'>\n\r"; $category_image_html .= "\t<span class='link_substitute' >\n\r"; $category_image_html .= "\t\t<span>" . __('N/A', 'wpsc') . "</span>\n\r"; $category_image_html .= "\t</span>\n\r"; $category_image_html .= "</span>\n\r"; } } // get the list of products associated with this category. $tags_to_replace = array('[wpsc_category_name]', '[wpsc_category_description]', '[wpsc_category_url]', '[wpsc_category_id]', '[wpsc_category_classes]', '[wpsc_category_image]', '[wpsc_subcategory]', '[wpsc_category_products_count]'); $content_to_place = array(esc_html($category_row->name), $category_description, esc_url(get_term_link($category_row->slug, 'wpsc_product_category')), $category_row->term_id, $category_classes, $category_image_html, $sub_categories, $category_count_html); // Stick all the category html together and concatenate it to the previously generated HTML $output .= str_replace($tags_to_replace, $content_to_place, $category_html); } return $output; }