Make WordPress Core

Changeset 11139


Ignore:
Timestamp:
04/30/2009 04:29:40 PM (16 years ago)
Author:
ryan
Message:

cat_row fixes. Props hailin. fixes #9661 see #8632

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r11133 r11139  
    2222 */
    2323function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
     24   
    2425    $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   
    2643}
    2744
     
    3956 * @return unknown
    4057 */
    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 
     58function _cat_rows( $parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count ) {
     59   
    5460    $start = ($page - 1) * $per_page;
    5561    $end = $start + $per_page;
    56     $i = -1;
    5762    ob_start();
    58     foreach ( $categories as $category ) {
     63   
     64    foreach ( $categories as $key => $category ) {
    5965        if ( $count >= $end )
    6066            break;
    61 
    62         $i++;
    63 
     67           
    6468        if ( $category->parent != $parent && empty($_GET['s']) )
    6569            continue;
     
    6771        // If the page starts in a subtree, print the parents.
    6872        if ( $count == $start && $category->parent > 0 ) {
     73           
    6974            $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 );
    7278                $my_parents[] = $my_parent;
    73                 if ( !$my_parent->parent )
     79                if ( $my_parent->parent == 0 )
    7480                    break;
    75                 $my_parent = $my_parent->parent;
     81                $p = $my_parent->parent;
    7682            }
     83           
    7784            $num_parents = count($my_parents);
    7885            while( $my_parent = array_pop($my_parents) ) {
     
    8592            echo "\t" . _cat_row( $category, $level );
    8693
    87         unset($categories[$i]); // Prune the working set
     94        unset( $categories[ $key ] );
     95       
    8896        $count++;
    8997
    9098        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 );
    93100    }
    94101
Note: See TracChangeset for help on using the changeset viewer.