wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
get_category_by_path [ WordPress Function ]
| Parameter: |
|
| Gibt zurück: |
|
| Definiert in: |
|
Retrieve category based on URL containing the category slug.
Breaks the $category_path parameter up to get the category slug.
Tries to find the child path and will return it. If it doesn't find a match, then it will return the first category matching slug, if $full_match, is set to false. If it does not, then it will return null.
It is also possible that it will return a WP_Error object on failure. Check for it when using this function.
Source
<?php
function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {
$category_path = rawurlencode( urldecode( $category_path ) );
$category_path = str_replace( '%2F', '/', $category_path );
$category_path = str_replace( '%20', ' ', $category_path );
$category_paths = '/' . trim( $category_path, '/' );
$leaf_path = sanitize_title( basename( $category_paths ) );
$category_paths = explode( '/', $category_paths );
$full_path = '';
foreach ( (array) $category_paths as $pathdir )
$full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );
$categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) );
if ( empty( $categories ) )
return null;
foreach ( $categories as $category ) {
$path = '/' . $leaf_path;
$curcategory = $category;
while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) {
$curcategory = get_term( $curcategory->parent, 'category' );
if ( is_wp_error( $curcategory ) )
return $curcategory;
$path = '/' . $curcategory->slug . $path;
}
if ( $path == $full_path )
return get_category( $category->term_id, $output );
}
// If full matching is not required, return the first cat that matches the leaf.
if ( ! $full_match )
return get_category( $categories[0]->term_id, $output );
return null;
}
?>
Beispiele [ wp-snippets.com ]
Top Google Suchergebnisse
- Function Reference/get category by path « WordPress Codex
Description. Retrieve category based on URL containing the category slug. Breaks the $category_path parameter up to get the category slug. Tries to find the ...
codex.wordpress.org - Wordpress Get value of queried category in URL - Stack Overflow
... give you the first category given a URL. codex.wordpress.org/ Function_Reference/get_category_by_path – rexposadas Sep 13 '10 at 16:18 ...
stackoverflow.com - get_category_by_path | A HitchHackers guide through WordPress
Feb 12, 2011 ... function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {}. Retrieve category based on URL containing the ...
hitchhackerguide.com - Jose.gs
19, 0.3915, 29597168, get_category_by_path( ) . ... 26, 0.3933, 29617128, get_category_by_path( ) . ... 33, 0.3949, 29636936, get_category_by_path( ) .
www.jose.gs