0

I need to show in the sidebar determinate category and its children through category widget

The file starts with :

    <?php $categories = $this->getCategories() ?>
<?php if (count($categories) > 0): ?>
    <div class="block block-blog block-blog-categories">
        <?php if ($title = $this->getTitle()): ?>
            <div class="block-title">
                <strong><span><?php echo $this->__($title) ?></span></strong>
            </div>
        <?php endif; ?>
        <div class="block-content">
            <ul class="level0" id="wp-category-list">
                <?php if ($this->getDropdown()): ?>
                    <li class="level0 item">
                        <select name="blog-archive-dropdown" onchange="setLocation(this.value);">
                            <option value="<?php echo $this->helper('wordpress')->getUrl() ?>"><?php echo $this->__('Select Category') ?></option>
                            <?php foreach($categories as $category): ?>

How filter by category term or ID?

2

Please update the code template/wordpress/sidebar/widget/categories.phtml to include a 3rd level categories means children categories. I have done by following code.

<?php foreach($categories as $category): ?>
    <li class="level0 item<?php if ($this->isCurrentCategory($category)): ?> active<?php endif; ?>">
        <a  class="level0" href="<?php echo $category->getUrl() ?>" title="<?php echo $category->getName() ?>">
            <?php echo $category->getName() ?>
        </a><?php if ($this->getCount()): ?> (<?php echo $category->getPostCount() ?>)<?php endif; ?>
        <?php if ($this->getHierarchical()): ?>
            <?php $children = $children = $category->getChildrenCategories() ?>
            <?php if (count($children) > 0): ?>
                <ul class="level1">
                    <?php foreach($children as $child): ?>
                        <?php if ($child->getPostCount() > 0): ?>
                        <li class="level1 item<?php if ($this->isCurrentCategory($child)): ?> active<?php endif; ?>">
                            &raquo; <a href="<?php echo $child->getUrl() ?>" title="<?php echo $child->getName() ?>" class="level1"><?php echo $child->getName() ?></a><?php if ($this->getCount()): ?> (<?php echo $child->getPostCount() ?>)<?php endif; ?>
                                      <?php $children2 = $children2 = $child->getChildrenCategories() ?>
                                      <?php if (count($children2) > 0): ?>
                                          <ul class="level2">
                                              <?php foreach($children2 as $child2): ?>
                                                  <?php if ($child2->getPostCount() > 0): ?>
                                                      <li class="level12 item<?php if ($this->isCurrentCategory($child2)): ?> active<?php endif; ?>">
                                                          &raquo; <a href="<?php echo $child2->getUrl() ?>" title="<?php echo $child2->getName() ?>" class="level1"><?php echo $child2->getName() ?></a><?php if ($this->getCount()): ?> (<?php echo $child2->getPostCount() ?>)<?php endif; ?>
                                                      </li>
                                                  <?php endif; ?>
                                              <?php endforeach; ?>
                                          </ul>
                                      <?php endif; ?>
                        </li>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        <?php endif; ?>
    </li>
<?php endforeach; ?>
  • 2
    vah vishavas vah – Rakesh Jesadiya Sep 19 '17 at 10:39
  • I not need include 3rd level I need display only one category with it children – yavonz15 Sep 19 '17 at 10:40
  • @yavonz15 you can remove the last foreach and correspondent code if you don't want to include 3rd level categories. You can modify same code as per your need. – Vishwas Soni Sep 19 '17 at 10:46
  • @yavonz15 this link might help you: fishpig.co.uk/magento/wordpress-integration/… Btw, your question seems to be something different than your comments. – Vishwas Soni Sep 19 '17 at 10:49
0

I find solution

in the foreach insert this condition

<?php if ($category->getSlug() === 'myslugcategory'): ?>

the complete foreach is

                    <?php foreach($categories as $category): ?>
                <?php if ($category->getSlug() === 'myslugcategory'): ?>
                    <li class="level0 item<?php if ($this->isCurrentCategory($category)): ?> active<?php endif; ?>">
                        <a  class="level0" href="<?php echo $category->getUrl() ?>" title="<?php echo $category->getName() ?>">
                            <?php echo $category->getName() ?>
                        </a><?php if ($this->getCount()): ?> (<?php echo $category->getPostCount() ?>)<?php endif; ?>
                        <?php if ($this->getHierarchical()): ?>
                            <?php $children = $category->getChildrenTerms() ?>
                            <?php if (count($children) > 0): ?>
                                <ul class="level1">
                                    <?php foreach($children as $child): ?>
                                        <?php if ($child->getPostCount() > 0): ?>
                                        <li class="level1 item<?php if ($this->isCurrentCategory($child)): ?> active<?php endif; ?>"><a href="<?php echo $child->getUrl() ?>" title="<?php echo $child->getName() ?>" class="level1"><?php echo $child->getName() ?></a><?php if ($this->getCount()): ?> (<?php echo $child->getPostCount() ?>)<?php endif; ?>
                                        </li>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                </ul>
                            <?php endif; ?>
                        <?php endif; ?>
                    </li>
                <?php endif ?>

                <?php endforeach; ?>
  • 1
    Please accept this answer as correct if this works for you. it will help someone to know the correct answer. – Vishwas Soni Sep 19 '17 at 11:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.