Search code examples
phpwordpressmagentofishpig

WP Magento Fishpig: How to display subcategory


I am trying to display the subcategory of a term in magento wordpress integration ie: my current term is topics in topics I have subcategories which is - funny, news and special.

What i am trying to do is in wordpress/term/view I need to show all of the current subcategories of the current term then on each sub categories I need to show the title of each post.

Here is what I have tried so far:

<div class="row" id="fisherman">
<div class="col-lg-12">
    <?php $_term = $this->getTerm() ?>
    <?php echo '<pre>';var_dump($_term);echo '</pre>'; die;?>
    <?php if ($_term): ?>
        <h2><?php echo $this->escapeHtml($_term->getName()) ?>  </h2>
        <?php if ($description = $_term->getDescription()): ?>
            <h4 class="description text-white text-center"><?php echo $description ?></h4>
        <?php endif; ?>
        <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-6" id="instagram">
                <span class="ig-follow pull-right" data-id="ab98fe2ce2" data-handle="redsbest" data-count="true" data-size="large" data-username="false"></span>
            </div>
            <script src="<?php echo $this->getSkinurl('dist/instagram/instagram.js'); ?>"></script>
            <script>(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src="//x.instagramfollowbutton.com/follow.js";s.parentNode.insertBefore(g,s);}(document,"script"));</script>
            <?php if ($postList = trim($this->getPostListHtml())): ?>
                <?php echo $postList ?>
            <?php else: ?>
                <p class="note-msg"><?php echo $this->__('There are no posts matching your selection.') ?></p>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <ul class="list-inline social-media">
        <li><a href="#" target="_blank" class="btn-lg btn-social btn"><i class="fa fa-facebook fa-6"></i></a></li>
        <li><a href="#" target="_blank" class="btn-lg btn-social btn"><i class="fa fa-instagram fa-6"></i></a></li>
        <li><a href="#" target="_blank" class="btn-lg btn-social btn"><i class="fa fa-twitter fa-6"></i></a></li>
    </ul>
</div>

however this one doesnt categorize any thing yet.. I tried calling $_term->getSubCategory(); and it returned null is this possible.. Sorry newbie here. And thanks in advance.


Solution

  • $subCateg = $_term->getChildrenTerms();
    

    As mentioned in fishpig documentation this method returns: a collection of child terms and If $_term was a category, this would return all subcategories.