0

I want to show down arrow when if the parent category has a child category. As of now, the code I'm working is showing the down arrow for all the parent categories even though it doesn't has a sub category.

I'm aware I have to write condition in order to achieve this but I'm not sure how to do it?

Could anyone please help me?

Below is the code I'm working on:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Top menu for store
 *
 * @var $block \Magento\Theme\Block\Html\Topmenu
 */
?>


    <link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/cart.css')?>">

  <?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Top menu for store
 *
 * @var $block \Magento\Theme\Block\Html\Topmenu
 */
?>

    <header class="headers">
  <div class="header-inrs">
    <div class="menu-container">
  <div class="menus">

    <ul class="clearfix backcolor designmenu">
      <?php
      $categories = $block->getStoreCategories();

foreach ($categories as $category):


  ?>  


      <li><a href="<?php echo $category->getRequestPath();?>"><i class="fa fa-angle-down" ></i><?php echo $category->getName(); ?></a>
 <ul>
<?php 
 $subCategories = $block->getCategoryById($category->getId());
      foreach ($subCategories->getChildrenCategories() as $subCategory):
        ?>

      <li><a href="<?php echo $subCategory->getRequestPath();?>"><?php echo $subCategory->getName(); ?></a>

          </li>

      <?php endforeach; ?>
       </ul>
      <?php endforeach; ?>
  </li>

   </ul>
  </div>
</div>
</div>

</header>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.