Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cateogory List with description and post count
<?php
add_shortcode('cat_listing', function($html){
$categories = get_categories();
$html = '';
foreach( $categories as $category ) {
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( $category->name ),
esc_html( $category->name )
);
$html .= '<h2>' . $category_link . '<sup>(' . $category->count . ')</sup></h2>';
$html .= '<p>' . $category->description . '</p>';
}
return $html;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment