从wordpress中的类别中提取同位素的过滤器

时间:2017-01-17 12:58:45

标签: wordpress filtering jquery-isotope taxonomy

我试图从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>

1 个答案:

答案 0 :(得分:1)

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

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

使用

$categories = get_categories();

请务必查看wordpress codex中的get_categories()页面。您可以指定一个可选的Array参数来设置顺序,或隐藏空类别或执行其他一些操作。

get_categories()

相关问题