Make WordPress Core


Ignore:
Timestamp:
02/27/2006 04:57:30 AM (19 years ago)
Author:
ryan
Message:

Bookmark/link rework. #2499

File:
1 edited

Legend:

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

    r3540 r3570  
    411411}
    412412
     413function &get_categories($args = '') {
     414    global $wpdb, $category_links;
     415
     416    parse_str($args, $r);
     417
     418    if ( !isset($r['type']) )  // 'post' or 'link'
     419        $r['type'] = 'post';
     420    if ( !isset($r['child_of']) )
     421        $r['child_of'] = 0;
     422    if ( !isset($r['orderby']) )
     423        $r['orderby'] = 'name';
     424    if ( !isset($r['order']) )
     425        $r['order'] = 'ASC';
     426    if ( !isset($r['hide_empty']) )
     427        $r['hide_empty'] = true;
     428
     429    $r['orderby'] = "cat_" . $r['orderby'];
     430
     431    $exclusions = '';
     432    if ( !empty($r['exclude']) ) {
     433        $excategories = preg_split('/[\s,]+/',$r['exclude']);
     434        if ( count($excategories) ) {
     435            foreach ( $excategories as $excat ) {
     436                $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
     437            }
     438        }
     439    }
     440
     441    $categories = $wpdb->get_results("SELECT * " .
     442        "FROM $wpdb->categories " .
     443        "$exclusions " .
     444        "ORDER BY " . $r['orderby'] . " " . $r['order']);
     445
     446    if ( empty($categories) )
     447        return array();
     448
     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); */
     465
     466    return $categories;
     467}
     468
    413469?>
Note: See TracChangeset for help on using the changeset viewer.