Changeset 11139
- Timestamp:
- 04/30/2009 04:29:40 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/template.php
r11133 r11139 22 22 */ 23 23 function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) { 24 24 25 $count = 0; 25 _cat_rows($categories, $count, $parent, $level, $page, $per_page); 26 27 if ( empty($categories) ) { 28 29 $args = array('hide_empty' => 0); 30 if ( !empty($_GET['s']) ) 31 $args['search'] = $_GET['s']; 32 33 $categories = get_categories( $args ); 34 35 if ( empty($categories) ) 36 return false; 37 } 38 39 $children = _get_term_hierarchy('category'); 40 41 _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count ); 42 26 43 } 27 44 … … 39 56 * @return unknown 40 57 */ 41 function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) { 42 if ( empty($categories) ) { 43 $args = array('hide_empty' => 0); 44 if ( !empty($_GET['s']) ) 45 $args['search'] = $_GET['s']; 46 $categories = get_categories( $args ); 47 } 48 49 if ( !$categories ) 50 return false; 51 52 $children = _get_term_hierarchy('category'); 53 58 function _cat_rows( $parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count ) { 59 54 60 $start = ($page - 1) * $per_page; 55 61 $end = $start + $per_page; 56 $i = -1;57 62 ob_start(); 58 foreach ( $categories as $category ) { 63 64 foreach ( $categories as $key => $category ) { 59 65 if ( $count >= $end ) 60 66 break; 61 62 $i++; 63 67 64 68 if ( $category->parent != $parent && empty($_GET['s']) ) 65 69 continue; … … 67 71 // If the page starts in a subtree, print the parents. 68 72 if ( $count == $start && $category->parent > 0 ) { 73 69 74 $my_parents = array(); 70 while ( $my_parent) { 71 $my_parent = get_category($my_parent); 75 $p = $category->parent; 76 while ( $p ) { 77 $my_parent = get_category( $p ); 72 78 $my_parents[] = $my_parent; 73 if ( !$my_parent->parent)79 if ( $my_parent->parent == 0 ) 74 80 break; 75 $ my_parent= $my_parent->parent;81 $p = $my_parent->parent; 76 82 } 83 77 84 $num_parents = count($my_parents); 78 85 while( $my_parent = array_pop($my_parents) ) { … … 85 92 echo "\t" . _cat_row( $category, $level ); 86 93 87 unset($categories[$i]); // Prune the working set 94 unset( $categories[ $key ] ); 95 88 96 $count++; 89 97 90 98 if ( isset($children[$category->term_id]) ) 91 _cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page ); 92 99 _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count ); 93 100 } 94 101
Note: See TracChangeset
for help on using the changeset viewer.