Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created May 10, 2013 07:28
Show Gist options
  • Save psdtohtml5/5552934 to your computer and use it in GitHub Desktop.
Save psdtohtml5/5552934 to your computer and use it in GitHub Desktop.
WordPress : Getting All Categories
<?php
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
//Getting all Categories
$categories = get_categories( $args );
foreach ($categories as $category) {
$separator = ' ';
$output = '';
$output .= '
<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">
<img src="'.$category->description.'"></a>'.$separator;//using category description as in image url
echo trim($output);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment