Changeset 1432
- Timestamp:
- 06/16/2004 04:40:40 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/admin-functions.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r1429 r1432 19 19 } 20 20 21 function get_nested_categories($default = 0) { 21 function return_categories_list( $parent = 0, $sortbyname = FALSE ) 22 { 23 /* 24 * This function returns an list of all categories 25 * that have $parent as their parent 26 * if no parent is specified we will assume top level caegories 27 * are required. 28 */ 29 global $wpdb; 30 31 // select sort order 32 $sort = "cat_id"; 33 if( TRUE == $sortbyname ) 34 { 35 $sort = "cat_name"; 36 } 37 38 // First query the database 39 $cats_tmp = $wpdb->get_results("SELECT cat_id FROM $wpdb->categories WHERE category_parent = $parent ORDER BY $sort"); 40 41 // Now strip this down to a simple array of IDs 42 $cats = array(); 43 if( count($cats_tmp) > 0 ) 44 { 45 foreach( $cats_tmp as $cat ) 46 { 47 $cats[] = $cat->cat_id; 48 } 49 } 50 51 // Return the list of categories 52 return $cats; 53 } 54 55 function get_nested_categories($default = 0, $parent = 0) { 22 56 global $post_ID, $mode, $wpdb; 23 57 … … 25 59 $checked_categories = $wpdb->get_col(" 26 60 SELECT category_id 27 FROM $wpdb->categories, $wpdb->post2cat61 FROM $wpdb->categories, $wpdb->post2cat 28 62 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 29 63 "); 64 65 if(count($checked_categories) == 0) 66 { 67 // No selected categories, strange 68 $checked_categories[] = $default; 69 } 70 30 71 } else { 31 72 $checked_categories[] = $default; 32 73 } 33 74 34 $cat egories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY category_parent DESC, cat_name ASC");75 $cats = return_categories_list($parent, TRUE); 35 76 $result = array(); 36 foreach($categories as $category) { 37 $array_category = get_object_vars($category); 38 $me = 0 + $category->cat_ID; 39 $parent = 0 + $category->category_parent; 40 if (isset($result[$me])) $array_category['children'] = $result[$me]; 41 $array_category['checked'] = in_array($category->cat_ID, $checked_categories); 42 $array_category['cat_name'] = stripslashes($category->cat_name); 43 $result[$parent][] = $array_category; 77 78 foreach($cats as $cat) 79 { 80 $result[$cat]['children'] = get_nested_categories($default, $cat); 81 $result[$cat]['cat_ID'] = $cat; 82 $result[$cat]['checked'] = in_array($cat, $checked_categories); 83 $result[$cat]['cat_name'] = stripslashes(get_the_category_by_ID($cat)); 44 84 } 45 85 46 return $result [0];86 return $result; 47 87 } 48 88
Note: See TracChangeset
for help on using the changeset viewer.