# 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.

+ + +
/wp-admin/edit.php" class="GET"> + + + +

Category Order

+ + +

/wp-admin/edit.php?page=wpguy_category_order_options&childrenOf=">« Back

+

+ +

Top level categories

+ + +
+
+ parent == $childrenOf){ + + echo "
"; + if(get_categories("hide_empty=0&child_of=$category->cat_ID")){ + echo "cat_ID\">More »"; + } + echo "

$category->name

"; + echo "
\n"; + + } + } + ?> +
+

+
+
+
+ + + + + + \ No newline at end of file diff -r 1e6e4baafa3d -r 6b96085291d7 web/wp-content/plugins/order-categories/readme.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/order-categories/readme.txt Tue Jan 05 09:48:24 2010 +0000 @@ -0,0 +1,36 @@ +=== Category Order === +Contributors: wp_guy +Donate link: http://wpguy.com/plugins/category-order +Tags: category, categories, order, reorder +Requires at least: 2.3 +Tested up to: 2.5.1 +Stable tag: trunk + +== Description == + +The Order Categories plugin allows you to easily reorder your categories the way you want via drag and drop. + +== Installation == + +To install the plugin just follow these simple steps: + +1. Download the plugin and expand it. +2. Copy the 'order-categories.php' file into your plugins folder (wp-content/plugins/). +3. Login into the WordPress administration area and go to the Plugins page. +4. Locate the Order Categories plugin and click on the activate link +5. That's it, now you can go to Manage > Order Categories and reorder the categories the way you want. +6. If you use wp_list_categories(), make sure you don't specify an order (e.g. wp_list_categories('orderby=count');). + +== Frequently Asked Questions == + += Does this plugin require me to overwrite WordPress core files? = + +No, there is nothing more you have to do except uploading and activating the plugin. + += Does this plugin allow me to reorder subcategories as well? = + +Yes it does. You'll see a 'more >' link next to the categories that have subcategories. Click on that link and you'll be able to reorder those subcategories. + += The Category Order panel seems to work fine but my categories are not reordered on my blog. What's going on? = + +Make sure you're not specifying an order in wp_list_categories() (e.g. wp_list_categories('orderby=count');) \ No newline at end of file