Changeset 3843 for trunk/wp-includes/functions.php
- Timestamp:
- 06/04/2006 09:36:52 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r3842 r3843 625 625 return $_page; 626 626 } 627 }628 629 function get_category_by_path($category_path, $full_match = true, $output = OBJECT) {630 global $wpdb;631 $category_path = rawurlencode(urldecode($category_path));632 $category_path = str_replace('%2F', '/', $category_path);633 $category_path = str_replace('%20', ' ', $category_path);634 $category_paths = '/' . trim($category_path, '/');635 $leaf_path = sanitize_title(basename($category_paths));636 $category_paths = explode('/', $category_paths);637 foreach($category_paths as $pathdir)638 $full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);639 640 $categories = $wpdb->get_results("SELECT cat_ID, category_nicename, category_parent FROM $wpdb->categories WHERE category_nicename = '$leaf_path'");641 642 if ( empty($categories) )643 return NULL;644 645 foreach ($categories as $category) {646 $path = '/' . $leaf_path;647 $curcategory = $category;648 while ($curcategory->category_parent != 0) {649 $curcategory = $wpdb->get_row("SELECT cat_ID, category_nicename, category_parent FROM $wpdb->categories WHERE cat_ID = '$curcategory->category_parent'");650 $path = '/' . $curcategory->category_nicename . $path;651 }652 653 if ( $path == $full_path )654 return get_category($category->cat_ID, $output);655 }656 657 // If full matching is not required, return the first cat that matches the leaf.658 if ( ! $full_match )659 return get_category($categories[0]->cat_ID, $output);660 661 return NULL;662 }663 664 // Retrieves category data given a category ID or category object.665 // Handles category caching.666 function &get_category(&$category, $output = OBJECT) {667 global $wpdb;668 669 if ( empty($category) )670 return null;671 672 if ( is_object($category) ) {673 wp_cache_add($category->cat_ID, $category, 'category');674 $_category = $category;675 } else {676 if ( ! $_category = wp_cache_get($category, 'category') ) {677 $_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category' LIMIT 1");678 wp_cache_add($category, $_category, 'category');679 }680 }681 682 if ( $output == OBJECT ) {683 return $_category;684 } elseif ( $output == ARRAY_A ) {685 return get_object_vars($_category);686 } elseif ( $output == ARRAY_N ) {687 return array_values(get_object_vars($_category));688 } else {689 return $_category;690 }691 }692 693 function get_catname($cat_ID) {694 $category = &get_category($cat_ID);695 return $category->cat_name;696 }697 698 function get_all_category_ids() {699 global $wpdb;700 701 if ( ! $cat_ids = wp_cache_get('all_category_ids', 'category') ) {702 $cat_ids = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");703 wp_cache_add('all_category_ids', $cat_ids, 'category');704 }705 706 return $cat_ids;707 627 } 708 628
Note: See TracChangeset
for help on using the changeset viewer.