git-svn-id: http://svn.automattic.com/wordpress/trunk@11139 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cd77f8c3a5
commit
c206ed413c
|
@ -21,8 +21,25 @@
|
||||||
* @param unknown_type $per_page
|
* @param unknown_type $per_page
|
||||||
*/
|
*/
|
||||||
function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
|
function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
_cat_rows($categories, $count, $parent, $level, $page, $per_page);
|
|
||||||
|
if ( empty($categories) ) {
|
||||||
|
|
||||||
|
$args = array('hide_empty' => 0);
|
||||||
|
if ( !empty($_GET['s']) )
|
||||||
|
$args['search'] = $_GET['s'];
|
||||||
|
|
||||||
|
$categories = get_categories( $args );
|
||||||
|
|
||||||
|
if ( empty($categories) )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$children = _get_term_hierarchy('category');
|
||||||
|
|
||||||
|
_cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,42 +55,32 @@ function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_pag
|
||||||
* @param unknown_type $per_page
|
* @param unknown_type $per_page
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) {
|
function _cat_rows( $parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count ) {
|
||||||
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;
|
$start = ($page - 1) * $per_page;
|
||||||
$end = $start + $per_page;
|
$end = $start + $per_page;
|
||||||
$i = -1;
|
|
||||||
ob_start();
|
ob_start();
|
||||||
foreach ( $categories as $category ) {
|
|
||||||
|
foreach ( $categories as $key => $category ) {
|
||||||
if ( $count >= $end )
|
if ( $count >= $end )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
if ( $category->parent != $parent && empty($_GET['s']) )
|
if ( $category->parent != $parent && empty($_GET['s']) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If the page starts in a subtree, print the parents.
|
// If the page starts in a subtree, print the parents.
|
||||||
if ( $count == $start && $category->parent > 0 ) {
|
if ( $count == $start && $category->parent > 0 ) {
|
||||||
|
|
||||||
$my_parents = array();
|
$my_parents = array();
|
||||||
while ( $my_parent) {
|
$p = $category->parent;
|
||||||
$my_parent = get_category($my_parent);
|
while ( $p ) {
|
||||||
|
$my_parent = get_category( $p );
|
||||||
$my_parents[] = $my_parent;
|
$my_parents[] = $my_parent;
|
||||||
if ( !$my_parent->parent )
|
if ( $my_parent->parent == 0 )
|
||||||
break;
|
break;
|
||||||
$my_parent = $my_parent->parent;
|
$p = $my_parent->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
$num_parents = count($my_parents);
|
$num_parents = count($my_parents);
|
||||||
while( $my_parent = array_pop($my_parents) ) {
|
while( $my_parent = array_pop($my_parents) ) {
|
||||||
echo "\t" . _cat_row( $my_parent, $level - $num_parents );
|
echo "\t" . _cat_row( $my_parent, $level - $num_parents );
|
||||||
|
@ -84,12 +91,12 @@ function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $p
|
||||||
if ( $count >= $start )
|
if ( $count >= $start )
|
||||||
echo "\t" . _cat_row( $category, $level );
|
echo "\t" . _cat_row( $category, $level );
|
||||||
|
|
||||||
unset($categories[$i]); // Prune the working set
|
unset( $categories[ $key ] );
|
||||||
|
|
||||||
$count++;
|
$count++;
|
||||||
|
|
||||||
if ( isset($children[$category->term_id]) )
|
if ( isset($children[$category->term_id]) )
|
||||||
_cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page );
|
_cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = ob_get_contents();
|
$output = ob_get_contents();
|
||||||
|
|
Loading…
Reference in New Issue