Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Created January 16, 2022 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diggeddy/a1d2877c4099060b752238d0c85c248b to your computer and use it in GitHub Desktop.
Save diggeddy/a1d2877c4099060b752238d0c85c248b to your computer and use it in GitHub Desktop.
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