# HG changeset patch # User hurons@caf4f556-3d62-0410-8435-a86758001935 # Date 1262684904 0 # Node ID 6b96085291d77096a2e6c61e8b88bfb449e04567 # Parent 1e6e4baafa3d44f559a4db35ae0f19cedf29f5c5 install and test "order-categories" plug-in diff -r 1e6e4baafa3d -r 6b96085291d7 web/wp-content/plugins/order-categories/category-order.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/order-categories/category-order.php Tue Jan 05 09:48:24 2010 +0000 @@ -0,0 +1,262 @@ + $option){ + $master .= $option.","; + } + + $ids = explode(",", $master); + + // Add an 'order' item to every category + $i=0; + foreach($ids as $id){ + if($id != ""){ + foreach($terms as $n => $category){ + if(is_object($category) && $category->term_id == $id){ + $terms[$n]->order = $i; + $i++; + } + } + } + + // Add order 99999 to every category that wasn't manually ordered (so they appear at the end). This just usually happens when you've added a new category but didn't order it. + foreach($terms as $n => $category){ + if(is_object($category) && !isset($category->order)){ + $terms[$n]->order = 99999; + } + } + + } + + // Sort the array of categories using a callback function + usort($terms, "wpguy_category_order_compare"); + } + + } + + return $terms; + } + + // Compare function. Used to order the categories array. + function wpguy_category_order_compare($a, $b) { + + if ($a->order == $b->order) { + + if($a->name == $b->name){ + return 0; + }else{ + return ($a->name < $b->name) ? -1 : 1; + } + + } + + return ($a->order < $b->order) ? -1 : 1; + } + + function wpguy_category_order_options(){ + if(isset($_GET['childrenOf'])){ + $childrenOf = $_GET['childrenOf']; + }else{ + $childrenOf = 0; + } + + + $options = get_option("wpguy_category_order"); + $order = $options[$childrenOf]; + + + if(isset($_GET['submit'])){ + $options[$childrenOf] = $order = $_GET['category_order']; + update_option("wpguy_category_order", $options); + $updated = true; + } + + // Get the parent ID of the current category and the name of the current category. + $allthecategories = get_categories("hide_empty=0"); + if($childrenOf != 0){ + foreach($allthecategories as $category){ + if($category->cat_ID == $childrenOf){ + $father = $category->parent; + $current_name = $category->name; + } + } + + } + + // Get only the categories belonging to the current category + $categories = get_categories("hide_empty=0&child_of=$childrenOf"); + + // Order the categories. + if($order){ + $order_array = explode(",", $order); + + $i=0; + + foreach($order_array as $id){ + foreach($categories as $n => $category){ + if(is_object($category) && $category->term_id == $id){ + $categories[$n]->order = $i; + $i++; + } + } + + + foreach($categories as $n => $category){ + if(is_object($category) && !isset($category->order)){ + $categories[$n]->order = 99999; + } + } + + } + + usort($categories, "wpguy_category_order_compare"); + + + } + + ?> + +
Changes Saved.