从同位素的 wordpress 类别中呈现过滤器

Rendering out filters from categories in wordpress for isotope

我正在尝试从 wordpress 中渲染类别以充当我的投资组合的同位素过滤器。

我已经开始执行以下操作,但无法渲染任何内容

<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>

正如 htmlbrewery 提到的那样,只需替换

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

$categories = get_categories();

一定要查看 wordpress codex 中的 get_categories() 页面。因为你可以指定一个可选的数组参数来设置顺序,或者隐藏空类别或者做一些其他的事情。

get_categories()