| 270 | | $r['hierarchical'] = true; |
|---|
| 271 | | |
|---|
| 272 | | return list_cats($r['optionall'], $r['all'], $r['sort_column'], $r['sort_order'], $r['file'], $r['list'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image'], $r['exclude'], $r['hierarchical']); |
|---|
| | 264 | $r['hierarchical'] = false; |
|---|
| | 265 | if ( !isset($r['title_li']) ) |
|---|
| | 266 | $r['title_li'] = ''; |
|---|
| | 267 | |
|---|
| | 268 | $q['orderby'] = $r['sort_column']; |
|---|
| | 269 | $q['order'] = $r['sort_order']; |
|---|
| | 270 | $q['include_last_update_time'] = $r['optiondates']; |
|---|
| | 271 | |
|---|
| | 272 | extract($r); |
|---|
| | 273 | |
|---|
| | 274 | $args = add_query_arg($q, $args); |
|---|
| | 275 | $categories = get_categories($args); |
|---|
| | 276 | |
|---|
| | 277 | $output = ''; |
|---|
| | 278 | if ( $title_li && $list ) |
|---|
| | 279 | $output = '<li class="categories">' . $r['title_li'] . '<ul>'; |
|---|
| | 280 | |
|---|
| | 281 | if ( empty($categories) ) { |
|---|
| | 282 | if ( $list) |
|---|
| | 283 | $output .= '<li>' . __("No categories") . '</li>'; |
|---|
| | 284 | else |
|---|
| | 285 | $output .= __("No categories"); |
|---|
| | 286 | } else { |
|---|
| | 287 | global $wp_query; |
|---|
| | 288 | $current_category = $wp_query->get_queried_object_id(); |
|---|
| | 289 | if ( $hierarchical ) |
|---|
| | 290 | $depth = 0; // Walk the full depth. |
|---|
| | 291 | else |
|---|
| | 292 | $depth = -1; // Flat. |
|---|
| | 293 | |
|---|
| | 294 | $output .= walk_category_tree($categories, $depth, '_category_list_element_start', '_category_list_element_end', '_category_list_level_start', '_category_list_level_end', $current_category, $r); |
|---|
| | 295 | } |
|---|
| | 296 | |
|---|
| | 297 | if ( $title_li && $list ) |
|---|
| | 298 | $output .= '</ul></li>'; |
|---|
| | 299 | |
|---|
| | 300 | echo apply_filters('list_cats', $output); |
|---|
| | 301 | } |
|---|
| | 302 | |
|---|
| | 303 | function _category_list_level_start($output, $depth, $cat, $args) { |
|---|
| | 304 | if (! $args['list']) |
|---|
| | 305 | return $output; |
|---|
| | 306 | |
|---|
| | 307 | $indent = str_repeat("\t", $depth); |
|---|
| | 308 | $output .= "$indent<ul class='children'>\n"; |
|---|
| | 309 | return $output; |
|---|
| | 310 | } |
|---|
| | 311 | |
|---|
| | 312 | function _category_list_level_end($output, $depth, $cat, $args) { |
|---|
| | 313 | if (! $args['list']) |
|---|
| | 314 | return $output; |
|---|
| | 315 | |
|---|
| | 316 | $indent = str_repeat("\t", $depth); |
|---|
| | 317 | $output .= "$indent</ul>\n"; |
|---|
| | 318 | return $output; |
|---|
| | 319 | } |
|---|
| | 320 | |
|---|
| | 321 | function _category_list_element_start($output, $category, $depth, $current_category, $args) { |
|---|
| | 322 | extract($args); |
|---|
| | 323 | |
|---|
| | 324 | $link = '<a href="' . get_category_link($category->cat_ID) . '" '; |
|---|
| | 325 | if ( $use_desc_for_title == 0 || empty($category->category_description) ) |
|---|
| | 326 | $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"'; |
|---|
| | 327 | else |
|---|
| | 328 | $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"'; |
|---|
| | 329 | $link .= '>'; |
|---|
| | 330 | $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>'; |
|---|
| | 331 | |
|---|
| | 332 | if ( (! empty($feed_image)) || (! empty($feed)) ) { |
|---|
| | 333 | $link .= ' '; |
|---|
| | 334 | |
|---|
| | 335 | if ( empty($feed_image) ) |
|---|
| | 336 | $link .= '('; |
|---|
| | 337 | |
|---|
| | 338 | $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"'; |
|---|
| | 339 | |
|---|
| | 340 | if ( !empty($feed) ) { |
|---|
| | 341 | $title = ' title="' . $feed . '"'; |
|---|
| | 342 | $alt = ' alt="' . $feed . '"'; |
|---|
| | 343 | $name = $feed; |
|---|
| | 344 | $link .= $title; |
|---|
| | 345 | } |
|---|
| | 346 | |
|---|
| | 347 | $link .= '>'; |
|---|
| | 348 | |
|---|
| | 349 | if ( !empty($feed_image) ) |
|---|
| | 350 | $link .= "<img src='$feed_image' $alt$title" . ' />'; |
|---|
| | 351 | else |
|---|
| | 352 | $link .= $name; |
|---|
| | 353 | $link .= '</a>'; |
|---|
| | 354 | if (empty($feed_image)) |
|---|
| | 355 | $link .= ')'; |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | if ( intval($optioncount) == 1 ) |
|---|
| | 359 | $link .= ' ('.intval($category->category_count).')'; |
|---|
| | 360 | |
|---|
| | 361 | if ( $optiondates ) { |
|---|
| | 362 | if ( $optiondates == 1 ) |
|---|
| | 363 | $optiondates = 'Y-m-d'; |
|---|
| | 364 | $link .= ' ' . gmdate($optiondates,$category->last_update_timestamp); |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | if ( $list ) { |
|---|
| | 368 | $output .= "\t<li"; |
|---|
| | 369 | if ( ($category->cat_ID == $current_category) && is_category() ) |
|---|
| | 370 | $output .= ' class="current-cat"'; |
|---|
| | 371 | $output .= ">$link\n"; |
|---|
| | 372 | } else { |
|---|
| | 373 | $output .= "\t$link<br />\n"; |
|---|
| | 374 | } |
|---|
| | 375 | |
|---|
| | 376 | return $output; |
|---|
| | 377 | } |
|---|
| | 378 | |
|---|
| | 379 | function _category_list_element_end($output, $category, $depth, $cat, $args) { |
|---|
| | 380 | if (! $args['list']) |
|---|
| | 381 | return $output; |
|---|
| | 382 | |
|---|
| | 383 | $output .= "</li>\n"; |
|---|
| | 384 | return $output; |
|---|
| 276 | | global $wpdb, $wp_query; |
|---|
| 277 | | // Optiondates now works |
|---|
| 278 | | if ( '' == $file ) |
|---|
| 279 | | $file = get_settings('home') . '/'; |
|---|
| 280 | | |
|---|
| 281 | | $exclusions = ''; |
|---|
| 282 | | if ( !empty($exclude) ) { |
|---|
| 283 | | $excats = preg_split('/[\s,]+/',$exclude); |
|---|
| 284 | | if ( count($excats) ) { |
|---|
| 285 | | foreach ( $excats as $excat ) { |
|---|
| 286 | | $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' '; |
|---|
| 287 | | } |
|---|
| 288 | | } |
|---|
| 289 | | } |
|---|
| 290 | | |
|---|
| 291 | | $exclusions = apply_filters('list_cats_exclusions', $exclusions ); |
|---|
| 292 | | |
|---|
| 293 | | if ( intval($categories) == 0 ) { |
|---|
| 294 | | $sort_column = 'cat_'.$sort_column; |
|---|
| 295 | | |
|---|
| 296 | | $query = " |
|---|
| 297 | | SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, category_count |
|---|
| 298 | | FROM $wpdb->categories |
|---|
| 299 | | WHERE cat_ID > 0 $exclusions |
|---|
| 300 | | ORDER BY $sort_column $sort_order"; |
|---|
| 301 | | |
|---|
| 302 | | $categories = $wpdb->get_results($query); |
|---|
| 303 | | } |
|---|
| 304 | | |
|---|
| 305 | | if ( $optiondates ) { |
|---|
| 306 | | $cat_dates = $wpdb->get_results(" SELECT category_id, |
|---|
| 307 | | UNIX_TIMESTAMP( MAX(post_date) ) AS ts |
|---|
| 308 | | FROM $wpdb->posts, $wpdb->post2cat, $wpdb->categories |
|---|
| 309 | | WHERE post_type = 'post' AND post_status = 'publish' AND post_id = ID $exclusions |
|---|
| 310 | | GROUP BY category_id"); |
|---|
| 311 | | foreach ( $cat_dates as $cat_date ) { |
|---|
| 312 | | $category_timestamp["$cat_date->category_id"] = $cat_date->ts; |
|---|
| 313 | | } |
|---|
| 314 | | } |
|---|
| 315 | | |
|---|
| 316 | | $num_found=0; |
|---|
| 317 | | $thelist = ""; |
|---|
| 318 | | |
|---|
| 319 | | foreach ( $categories as $category ) { |
|---|
| 320 | | if ( ( intval($hide_empty) == 0 || $category->category_count) && (!$hierarchical || $category->category_parent == $child_of) ) { |
|---|
| 321 | | $num_found++; |
|---|
| 322 | | $link = '<a href="'.get_category_link($category->cat_ID).'" '; |
|---|
| 323 | | if ( $use_desc_for_title == 0 || empty($category->category_description) ) |
|---|
| 324 | | $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"'; |
|---|
| 325 | | else |
|---|
| 326 | | $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"'; |
|---|
| 327 | | $link .= '>'; |
|---|
| 328 | | $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>'; |
|---|
| 329 | | |
|---|
| 330 | | if ( (! empty($feed_image)) || (! empty($feed)) ) { |
|---|
| 331 | | |
|---|
| 332 | | $link .= ' '; |
|---|
| 333 | | |
|---|
| 334 | | if ( empty($feed_image) ) |
|---|
| 335 | | $link .= '('; |
|---|
| 336 | | |
|---|
| 337 | | $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"'; |
|---|
| 338 | | |
|---|
| 339 | | if ( !empty($feed) ) { |
|---|
| 340 | | $title = ' title="' . $feed . '"'; |
|---|
| 341 | | $alt = ' alt="' . $feed . '"'; |
|---|
| 342 | | $name = $feed; |
|---|
| 343 | | $link .= $title; |
|---|
| 344 | | } |
|---|
| 345 | | |
|---|
| 346 | | $link .= '>'; |
|---|
| 347 | | |
|---|
| 348 | | if ( !empty($feed_image) ) |
|---|
| 349 | | $link .= "<img src='$feed_image' $alt$title" . ' />'; |
|---|
| 350 | | else |
|---|
| 351 | | $link .= $name; |
|---|
| 352 | | |
|---|
| 353 | | $link .= '</a>'; |
|---|
| 354 | | |
|---|
| 355 | | if (empty($feed_image)) |
|---|
| 356 | | $link .= ')'; |
|---|
| 357 | | } |
|---|
| 358 | | |
|---|
| 359 | | if ( intval($optioncount) == 1 ) |
|---|
| 360 | | $link .= ' ('.intval($category->category_count).')'; |
|---|
| 361 | | |
|---|
| 362 | | if ( $optiondates ) { |
|---|
| 363 | | if ( $optiondates == 1 ) |
|---|
| 364 | | $optiondates = 'Y-m-d'; |
|---|
| 365 | | $link .= ' ' . gmdate($optiondates, $category_timestamp["$category->cat_ID"]); |
|---|
| 366 | | } |
|---|
| 367 | | |
|---|
| 368 | | if ( $list ) { |
|---|
| 369 | | $thelist .= "\t<li"; |
|---|
| 370 | | if (($category->cat_ID == $wp_query->get_queried_object_id()) && is_category()) { |
|---|
| 371 | | $thelist .= ' class="current-cat"'; |
|---|
| 372 | | } |
|---|
| 373 | | $thelist .= ">$link\n"; |
|---|
| 374 | | } else { |
|---|
| 375 | | $thelist .= "\t$link<br />\n"; |
|---|
| 376 | | } |
|---|
| 377 | | |
|---|
| 378 | | if ($hierarchical && $children) |
|---|
| 379 | | $thelist .= list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical); |
|---|
| 380 | | if ($list) |
|---|
| 381 | | $thelist .= "</li>\n"; |
|---|
| 382 | | } |
|---|
| 383 | | } |
|---|
| 384 | | if ( !$num_found && !$child_of ) { |
|---|
| 385 | | if ( $list ) { |
|---|
| 386 | | $before = '<li>'; |
|---|
| 387 | | $after = '</li>'; |
|---|
| 388 | | } |
|---|
| 389 | | echo $before . __("No categories") . $after . "\n"; |
|---|
| 390 | | return; |
|---|
| 391 | | } |
|---|
| 392 | | if ( $list && $child_of && $num_found && $recurse ) { |
|---|
| 393 | | $pre = "\t\t<ul class='children'>"; |
|---|
| 394 | | $post = "\t\t</ul>\n"; |
|---|
| 395 | | } else { |
|---|
| 396 | | $pre = $post = ''; |
|---|
| 397 | | } |
|---|
| 398 | | $thelist = $pre . $thelist . $post; |
|---|
| 399 | | if ( $recurse ) |
|---|
| 400 | | return $thelist; |
|---|
| 401 | | echo apply_filters('list_cats', $thelist); |
|---|
| | 388 | $query = "optionall=$optionall&all=$all&sort_column=$sort_column&sort_order=$sort_order&list=$list&optiondates=$optiondates&optioncount=$optioncount&hide_empty=$hide_empty&use_desc_for_title=$use_desc_for_title&child_of=$child_of&feed=$feed&feed_image=$feed_image&exclude=$exclude&hierarchical=$hierarchical"; |
|---|
| | 389 | return wp_list_cats($query); |
|---|
| 449 | | if ( $r['hide_empty'] ) { |
|---|
| 450 | | foreach ( $categories as $category ) { |
|---|
| 451 | | $count = 0; |
|---|
| 452 | | if ( 'link' == $r['type'] ) { |
|---|
| 453 | | $count = $category->link_count; |
|---|
| 454 | | } else { |
|---|
| 455 | | $count = $category->category_count; |
|---|
| 456 | | } |
|---|
| 457 | | if ( $count ) |
|---|
| 458 | | $the_categories[] = $category; |
|---|
| 459 | | } |
|---|
| 460 | | $categories = $the_categories; |
|---|
| 461 | | } |
|---|
| 462 | | |
|---|
| 463 | | /* if ( $r['child_of'] ) |
|---|
| 464 | | $categories = & get_category_children($r['child_of'], $categories); */ |
|---|
| | 469 | if ( $include_last_update_time ) { |
|---|
| | 470 | $stamps = $wpdb->get_results("SELECT category_id, UNIX_TIMESTAMP( MAX(post_date) ) AS ts FROM $wpdb->posts, $wpdb->post2cat, $wpdb->categories |
|---|
| | 471 | WHERE post_status = 'publish' AND post_id = ID AND $where GROUP BY category_id"); |
|---|
| | 472 | global $cat_stamps; |
|---|
| | 473 | foreach ($stamps as $stamp) |
|---|
| | 474 | $cat_stamps[$stamp->category_id] = $stamp->ts; |
|---|
| | 475 | function stamp_cat($cat) { |
|---|
| | 476 | global $cat_stamps; |
|---|
| | 477 | $cat->last_update_timestamp = $cat_stamps[$cat->cat_ID]; |
|---|
| | 478 | return $cat; |
|---|
| | 479 | } |
|---|
| | 480 | $categories = array_map('stamp_cat', $categories); |
|---|
| | 481 | unset($cat_stamps); |
|---|
| | 482 | } |
|---|
| | 483 | |
|---|
| | 484 | if ( $child_of || $hierarchical ) |
|---|
| | 485 | $categories = & _get_cat_children($child_of, $categories); |
|---|