$value) $$key = $value; global $wpdb; $cal_tree = array(); if (!$column_count) $column_count = 1; function get_wp_version() { global $wp_version; preg_match("/\d\.\d/i", $wp_version, $match); // wpmu - increment version by 1.0 to match wp if (strpos($wp_version, 'wordpress-mu') !== false) { $match[0] = $match[0] + 1.0; } return $match[0]; } if (get_wp_version() == '2.1' || get_wp_version() == '2.2') { error_reporting(0); $wpdb->show_errors = false; } global $rssfeeds; $feed = ''; if ($rssfeeds) { $feed = 'RSS'; $show_parent_count = 0; $show_child_count = 0; } if (get_wp_version() < '2.3') { // for WP < 2.3 $parent_cats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_parent = 0 " . ( count($exclude_cat) ? ' AND cat_ID NOT IN (' . implode(',', $exclude_cat) . ') ' : '' ) . " ORDER BY cat_name"); foreach ($parent_cats as $parent) { $summ = "SELECT SUM(category_count) FROM $wpdb->categories WHERE category_parent = $parent->cat_ID"; $child_summ = mysql_result(mysql_query($summ),0); $cat_name = get_the_category_by_ID($parent->cat_ID); $descr = sprintf(__("View all posts filed under %s"), $cat_name); if ($desc_for_parent_title == 1) { if (empty($parent->category_description)) { $descr = sprintf(__("View all posts filed under %s"), $cat_name); } else { $descr = $parent->category_description; } } $child_summ += $parent->category_count; if ($show_parent_count == 1) { $parent_count = ' (' . $child_summ . ')'; } else { $parent_count = ''; } // перехват вывода ob_start(); wp_list_cats( ( count($exclude_cat) ? 'exclude=' . implode(',', $exclude_cat) : '' ) . '&optioncount=' . $show_child_count . '&hide_empty=' . $hide_empty . '&use_desc_for_title=' . $desc_for_child_title . '&child_of=' . $parent->cat_ID . '&hierarchical=1&feed=' . $feed); $echo = ob_get_contents(); ob_end_clean(); $cal_tree[] = array( 'cat' => array( 'href' => get_category_link($parent->cat_ID), 'title' => $descr, 'name' => $cat_name, 'count' => $parent_count ), 'cats'=> $echo ); } } // end for WP < 2.3 else { // for WP >= 2.3 $parent_cats = $wpdb->get_results("SELECT * FROM $wpdb->term_taxonomy term_taxonomy LEFT JOIN $wpdb->terms terms ON terms.term_id = term_taxonomy.term_id WHERE term_taxonomy.taxonomy = 'category' AND term_taxonomy.parent = 0 " . ( count($exclude_cat) ? ' AND terms.term_id NOT IN (' . implode(',', $exclude_cat) . ') ' : '' ) . " ORDER BY terms.name"); foreach ($parent_cats as $parent) { $summ = "SELECT SUM(count) FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' AND parent = $parent->term_id"; $child_summ = mysql_result(mysql_query($summ),0); $cat_name = get_the_category_by_ID($parent->term_id); $descr = sprintf(__("View all posts filed under %s"), $cat_name); if ($desc_for_parent_title == 1) { if (empty($parent->description)) { $descr = sprintf(__("View all posts filed under %s"), $cat_name); } else { $descr = $parent->description; } } $child_summ += $parent->count; if ($show_parent_count == 1) { $parent_count = ' (' . $child_summ . ')'; } else { $parent_count = ''; } $cal_tree[] = array( 'cat' => array( 'href' => get_category_link($parent->term_id), 'title' => $descr, 'name' => $cat_name, 'count' => $parent_count ), 'cats'=> wp_list_categories( ( count($exclude_cat) ? 'exclude=' . implode(',', $exclude_cat) : '' ) . '&show_count=' . $show_child_count . '&hide_empty=' . $hide_empty . '&use_desc_for_title=' . $desc_for_child_title . '&child_of=' . $parent->term_id . '&title_li=&hierarchical=' . $child_hierarchical . '&echo=0&feed=' . $feed) ); } } // end for WP >= 2.3 $_tree = array(); $count = count($cal_tree); if ($sort_direction) { $line_count = ceil( $count / $column_count ); $limit = $count - $line_count * $column_count % $count; for ($i = 0; $i < $count; $i++) { $index = floor($i / $line_count) + ($limit && $i > $limit ? 1 : 0); if (!isset($_tree[$index])) { $_tree[$index] = array(); } $_tree[$index][] = &$cal_tree[$i]; } } else { for ($i = 0; $i < $count; $i++) { $index = $i % $column_count; if (!isset($_tree[$index])) { $_tree[$index] = array(); } $_tree[$index][] = &$cal_tree[$i]; } } if (count($_tree)) { echo '