Search code examples
magentofishpig

Display all the Post Categories in Magento Fishpig


I've two Post Categories with two different layouts, But now both are displaying in the same view.phtml. I need to create a check in which category the post belongs and display the style accordingly.

By using below method, I can load a single category with ID 2.

<?php $test = Mage::getModel('wordpress/term')->load(2);?>

Is there any way to load all the post categories.?


Solution

  • Shyam is almost there. Here is a slightly cleaner version of the code:

    <?php $categories = $post->getTermCollection('category') ?>
    <?php if (count($categories) > 0): ?>
        <?php foreach($categories as $category): ?>
            <?php if ((int)$category->getId() === 1): ?>
                // Category ID #1
            <?php elseif ((int)$category->getId() === 2): ?>
                // Category ID #2       
            <?php else: ?>
                // All other categories
            <?php endif; ?>
        <?php endforeach; ?>
    <?php endif; ?>