Пример #1
0
function _cat_rows($categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20)
{
    if (empty($categories)) {
        $args = array('hide_empty' => 0);
        if (!empty($_GET['s'])) {
            $args['search'] = $_GET['s'];
        }
        $categories = get_categories($args);
    }
    if (!$categories) {
        return false;
    }
    $children = _get_term_hierarchy('category');
    $start = ($page - 1) * $per_page;
    $end = $start + $per_page;
    $i = -1;
    ob_start();
    foreach ($categories as $category) {
        if ($count >= $end) {
            break;
        }
        $i++;
        if ($category->parent != $parent) {
            continue;
        }
        // If the page starts in a subtree, print the parents.
        if ($count == $start && $category->parent > 0) {
            $my_parents = array();
            $my_parent = $category->parent;
            while ($my_parent) {
                $my_parent = get_category($my_parent);
                $my_parents[] = $my_parent;
                if (!$my_parent->parent) {
                    break;
                }
                $my_parent = $my_parent->parent;
            }
            $num_parents = count($my_parents);
            while ($my_parent = array_pop($my_parents)) {
                echo "\t" . _cat_row($my_parent, $level - $num_parents);
                $num_parents--;
            }
        }
        if ($count >= $start) {
            echo "\t" . _cat_row($category, $level);
        }
        unset($categories[$i]);
        // Prune the working set
        $count++;
        if (isset($children[$category->term_id])) {
            _cat_rows($categories, $count, $category->term_id, $level + 1, $page, $per_page);
        }
    }
    $output = ob_get_contents();
    ob_end_clean();
    $output = apply_filters('cat_rows', $output);
    echo $output;
}
Пример #2
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $categories
 * @param unknown_type $count
 * @param unknown_type $parent
 * @param unknown_type $level
 * @param unknown_type $page
 * @param unknown_type $per_page
 * @return unknown
 */
function _cat_rows($parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count)
{
    $start = ($page - 1) * $per_page;
    $end = $start + $per_page;
    ob_start();
    foreach ($categories as $key => $category) {
        if ($count >= $end) {
            break;
        }
        if ($category->parent != $parent && empty($_GET['s'])) {
            continue;
        }
        // If the page starts in a subtree, print the parents.
        if ($count == $start && $category->parent > 0) {
            $my_parents = array();
            $p = $category->parent;
            while ($p) {
                $my_parent = get_category($p);
                $my_parents[] = $my_parent;
                if ($my_parent->parent == 0) {
                    break;
                }
                $p = $my_parent->parent;
            }
            $num_parents = count($my_parents);
            while ($my_parent = array_pop($my_parents)) {
                echo "\t" . _cat_row($my_parent, $level - $num_parents);
                $num_parents--;
            }
        }
        if ($count >= $start) {
            echo "\t" . _cat_row($category, $level);
        }
        unset($categories[$key]);
        $count++;
        if (isset($children[$category->term_id])) {
            _cat_rows($category->term_id, $level + 1, $categories, $children, $page, $per_page, $count);
        }
    }
    $output = ob_get_contents();
    ob_end_clean();
    echo $output;
}