get_categories [ WordPress Function ]
get_categories ( $args = '' )
| Parameters: |
|
| Links: | |
| See: | |
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: get_category, wp_get_post_categories, get_category_link, wp_create_categories, get_category_parents
Retrieve list of category objects.
If you change the type to 'link' in the arguments, then the link categories will be returned instead. Also all categories will be updated to be backwards compatible with pre-2.3 plugins and themes.
Source
<?php
function &get_categories( $args = '' ) {
$defaults = array( 'taxonomy' => 'category' );
$args = wp_parse_args( $args, $defaults );
$taxonomy = apply_filters( 'get_categories_taxonomy', $args['taxonomy'], $args );
// Back compat
if ( isset($args['type']) && 'link' == $args['type'] ) {
_deprecated_argument( __FUNCTION__, '3.0', '' );
$taxonomy = $args['taxonomy'] = 'link_category';
}
$categories = (array) get_terms( $taxonomy, $args );
foreach ( array_keys( $categories ) as $k )
_make_cat_compat( $categories[$k] );
return $categories;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- get_categories - WordPress Codex
Description. Returns an array of category objects matching the query parameters. Arguments are pretty much the same as wp_list_categories and can be ...
codex.wordpress.org - php - wordpress get_categories() issue - Stack Overflow
I have created the function below which is intended to list the sub ... If you look at the docs at wordpress.org for get_posts() you will see that the ...
stackoverflow.com - SimplePie Documentation: get_categories()
Mar 6, 2011 ... class SimplePie_Item { get_categories ( [int $start = 0], [int $length = 0] ) }. Returns an array of SimplePie_Category objects that were found for ...
simplepie.org - Filter get_categories() for taxonomy term in WordPress
Dec 1, 2010 ... I want to show a category only if a (custom) post is in that category AND region = $name for that post. So, e.g. I have a custom post (type ...
wordpress.stackexchange.com
Gebruikersdiscussies [ wordpress.org ]
- leochan369 on "Pagination with get_categories"
- depatterson on "Find and display parent categories"
- depatterson on "Find and display parent categories"
- ErikStromme on "get_categories count shows 0 when not empty"
- kparker2 on "Custom taxonomy category menu building. Please help"
- dhechler on "Get Parent Categories as Checkbox Inputs"
- Akay Akagunduz on "get_categories() with taxonomy not working in function.php"
- duck__boy on "get_categories() with taxonomy not working in function.php"
- Akay Akagunduz on "get_categories() with taxonomy not working in function.php"
- Digital Raindrops on "get_categories() with taxonomy not working in function.php"
2 User Note(s)
This example basically works like wp_list_categories with the only difference that it doesn't show the number posts in this category in parentheses, but the number of comments in the category:
<ul>
<?php
$ausgabe = '';
$allcats = get_categories( array('hide_empty'=>true) );
if( $allcats ) {
foreach( $allcats as $category ) {
$catnum = '';
$catposts = get_posts('numberposts=-1&category=' . $category->term_id);
foreach( $catposts as $catpost ) {
$catnum = $catnum + get_comments_number( $catpost->ID );
}
$cat_name = attribute_escape( $category->name );
$cat_name = apply_filters( 'list_cats', $cat_name, $allcats );
$link = '<a href="' . get_category_link( $category->term_id ) . '" ';
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
$link .= '>';
$link .= $cat_name . '</a>';
$ausgabe .= '<li class="cat-item cat-item-' . $category->term_id . '">' . $link . ' (' . $catnum . ')</li>' . "\n";
$catposts = array();
}
$ausgabe = apply_filters('wp_list_categories', $ausgabe);
} else {
$ausgabe .= '<li>' . __("No categories") . '</li>';
}
echo $ausgabe;
?>
</ul>
$categories = get_categories('include=<IDofCategory>');foreach ($categories as $cat) {
echo $cat->category_count." posts";
}