Search code examples
wordpressfilteringjquery-isotopetaxonomy

Rendering out filters from categories in wordpress for isotope


I am trying to render out the categories from wordpress to act as the isotope filters for my portfolio.

I have started the following but cant get anything to render

<div class="filter-container isotopeFilters2">
    <ul class="list-inline filter">

        <?php $categories = get_the_category($post->ID);
            $count = 0;
            foreach($categories as $cd): 
            $count++;
            if($count == 1){ ?>
                <li><a href="#" class="active" data-filter="*">All</a></li>
            <?php } else { ?>
                <li><a href="#" data-filter=".<?php echo $cd->slug; ?>"><?php echo $cd->slug; ?></a></li>
            <?php } ?>

        <?php endforeach; ?>

    </ul>
</div>

Solution

  • As htmlbrewery mentioned just replace

    $categories = get_the_category($post->ID);
    

    With

    $categories = get_categories();
    

    Be sure to check out the get_categories() page in the wordpress codex. As you can specify an optional Array parameter to set order, or to hide empty categories or to do a bunch of other stuff.

    get_categories()