Created
June 4, 2010 19:11
-
-
Save envex/425821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Category Lister | |
Stolen from plugins/wp-e-commerce/wpsc-includes/category.functions.php - show_cats_brands() | |
*/ | |
function show_categories() { | |
global $wpdb; | |
$output = null; | |
//Get all the Categories | |
$category_group = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_CATEGORISATION_GROUPS."` WHERE `active` IN ('1') AND `default` IN ('1') LIMIT 1 "); | |
//Get all the categories again?! | |
$categories = $wpdb->get_results(" | |
SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` | |
WHERE `group_id` IN ('$category_group') | |
AND `active`='1' | |
AND `category_parent` = '0' | |
ORDER BY `name` | |
ASC",ARRAY_A | |
); | |
if($categories) { | |
foreach($categories as $option) { | |
//Display the main category | |
$output .= '<li class="page_item"><a class="productlink" href="' . wpsc_category_url($option['id']) . '">' . stripslashes($option['name']) . '</a>'; | |
$subcategories = $wpdb->get_results(" | |
SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` | |
WHERE `group_id` IN ('$category_group') | |
AND `active`='1' | |
AND `category_parent` = '" . $option['id'] . "' | |
ORDER BY `id`",ARRAY_A | |
); | |
if($subcategories != null) { | |
//$output .= display_subcategories($option['id']); | |
$subcategories = $wpdb->get_results( | |
"SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` | |
WHERE `active`='1' | |
AND `category_parent` = '".absint($option['id'])."' | |
ORDER BY `nice-name`",ARRAY_A | |
); | |
if($subcategories){ | |
$output .= '<ul class="page_item">'; | |
foreach($subcategories as $subcategory){ | |
$output .= '<li class="page_item"><a href="' . wpsc_category_url($subcategory['id']) . '">' . stripslashes($subcategory['name']) . '</a></li>'; | |
} | |
$output .= "</ul>"; | |
} | |
} | |
} | |
$output .= '</li>'; | |
} | |
echo $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment