R
R
Ruslan Makarov2016-03-01 16:28:35
PHP
Ruslan Makarov, 2016-03-01 16:28:35

Displaying WordPress subcategories, how to hide an empty block when there are none?

Good day!
The essence of the question is in the title...
Tell me please, I just can't figure it out myself... I'm not strong in php...
I'm on the category page, I display subcategories with the code:

<div class="panel panel-primary">
              <div class="panel-heading">
                <h3 class="panel-title">Подкатегории</h3>
              </div>
              <div class="panel-body">
                <ul class="list-inline">
                  <?php if (count(get_categories('child_of='.$cat))) //Если в текущей категории нет подрубрик, не отображаем... ?>
                    <?php if (is_category()) { ?>
                    <?php $current_cat=get_query_var('cat'); //если ее убрать, то будет выводиться весь список рубрик стайта
                          wp_list_categories('child_of='.$current_cat.'&title_li=&show_count=1');} ?>
                </ul>
              </div>
            </div>

But, if there are no subcategories in the category or it is "closing", then an empty block is displayed ...
How can I make sure that if there are none, the entire block is not displayed?
Screenshots for clarity:
Where there are subcategories - all the rules
7666f23aa6f6402497a052f096619a26.png
Where not - how to hide this block?
b139ef681db9446e899d89e0c3f87d6e.png
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilyas Galiev, 2016-03-01
@facepook

line

<?php if (count(get_categories('child_of='.$cat))) : ?>

place before the block, and the line <?php endif;?>
after the closing tag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question