Created
January 16, 2022 11:48
-
-
Save diggeddy/a1d2877c4099060b752238d0c85c248b to your computer and use it in GitHub Desktop.
Cateogory List with description and post count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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