【问题标题】:Rendering out filters from categories in wordpress for isotope从 wordpress 中的同位素类别中渲染过滤器
【发布时间】:2017-11-02 06:38:05
【问题描述】:

我正在尝试渲染 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>

【问题讨论】:

  • 我很久没有真正使用过 wordpress,但对我来说,您似乎没有得到所有类别,而是分配给特定帖子的类别?
  • @deadfishli 没错,@Neil 请使用此功能get_categories

标签: wordpress filtering jquery-isotope taxonomy


【解决方案1】:

正如 htmlbrewery 提到的,只需替换

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

$categories = get_categories();

请务必查看 wordpress codex 中的 get_categories() 页面。你可以指定一个可选的 Array 参数来设置顺序,或者隐藏空类别或做很多其他事情。

get_categories()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 2019-08-11
    • 1970-01-01
    • 2015-02-25
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多