Displaying Categories list – Custom post type texonomy list in wordpress by shortcode

with below shortcode ypu can Displays list of your custom post type Categories in a grid. The categories can be displayed in two modes. Either just the most top categories or categories and sub categories underneath.

Display top categories in specific count columns and do not display total count
of post

[cpt_categories show=”top” columns=”4″ show_count=”0″]

Display all categories in specific count columns, display max. 5 sub categories for each top category and than View all category link

[cpt_categories show=”all” columns=”4″ sub_count=”5″]

To see complete code .. click me

<code>

<?php

add_shortcode(‘cpt_categories’, ‘shortcode_cpt_categories’);
function shortcode_cpt_categories( $atts ) {

extract(shortcode_atts(array(
‘name’ => ‘default’,
‘show’ => ‘top’,
‘columns’ => 4,
‘show_count’ => true,
‘sub_count’ => 5

), $atts));

$columns = “flexbox-columns-” . (int)$columns;

if($show != ‘top’) {$show = ‘all’;}

$terms = get_terms( ‘cpt_category_name’, array(
‘hide_empty’ => 0,
‘parent’ => null,
) );

wp_enqueue_style( ‘add_here_css_file_if_need’);
ob_start();

if($show==’all’)
{
if(!empty($terms)): ?>

slug ?>”> “>
name) ?>

<?php endforeach; ?>
</div>
<?php else: ?>

</div>
<?php endif;
}
else
{

if(!empty($terms)): ?>

slug ?>”> “>
name) ?>

<?php endforeach; ?>
</div>
<?php
else: ?>

</div>
<?php endif;
}
return ob_get_clean();

}

?>

</code>