How to hide categories with zero posts
-
I want to hide the categories with zero posts.
and also i want to hide specific category with its id.How can i do this?
Here is my code
//—————————————————–
// Display all categories
//—————————————————–
function mn_display_all_cats()
{
global $post;
$disable_cat_list = get_theme_mod(‘disable_categories_list’);
if ($disable_cat_list == 0) { ?>
<div class=”clearfix”></div>
<div id=”allcategories” class=”display-categories”>
<p class=”text-uppercase font-weight-light mb-0″>
<?php _e(‘Categories’, ‘mundana’); ?>
</p>
<div class=”w-100 d-block swiper-container circle”>
<!– swiper wrapper –>
<div class=”d-flex _gtodKlsd swiper-wrapper”>
<!– circle html –>
<?php
$display_categories = get_categories(array(
‘orderby’ => ‘name’,
‘order’ => ‘ASC’
));
foreach ($display_categories as $category) { ?>
<div class=”pt-3 d-flex _Koqas swiper-slide”>
<div class=”h-100 w-100″>
<div class=”position-relative d-inline-block postmgs loading”><div class=”position-relative”>
<?php if (function_exists(‘z_taxonomy_image_url’)) {
if (z_taxonomy_image_url($category->term_id)) { ?>
term_id)); ?>”>
term_id); ?>” class=”_OsdKkas b-g” width=”64″ height=”64″/>
<?php
}
} ?></div>
<?php
$category_link = sprintf(
‘%3$s‘,
esc_url(get_category_link($category->term_id)),
esc_attr(sprintf(__(‘View all posts in %s’, ‘mundana’), $category->name)),
esc_html($category->name)
);
echo ‘<p class=”_cabnvibcd mt-2 mb-0 posttxt”><span class=”_aftnrnu mt-2″>’ . sprintf(esc_html__(‘%s’, ‘mundana’), $category_link) . ‘</span></p> ‘; ?></div>
</div>
</div>
<?php
} ?>
</div>
<div id=”prevb2″ class=”swiper-button-prev”></div>
<div id=”nextb2″ class=”swiper-button-next”></div>
<!– swiper wrapper –>
</div>
</div><?php
}
}The page I need help with: [log in to see the link]
- The topic ‘How to hide categories with zero posts’ is closed to new replies.