简体   繁体   English

WordPress获取术语,但删除某些过滤器(如果存在)

[英]Wordpress get terms but remove certain filter if it exists

I have an image gallery, which has some filter controls. 我有一个图库,其中包含一些过滤器控件。 Now they work fine, all is well. 现在他们工作正常,一切都很好。 The only thing that I need to do is remove the featured filter from showing on the gallery page, as this is only used to help pull out images on the homepage. 我唯一需要做的是从图库页面上删除featured过滤器,因为这仅用于帮助提取首页上的图像。

Currently on my projects page, I have this creating the list items which are links to the filter slugs. 当前,在我的项目页面上,我正在创建列表项,这些列表项是指向过滤器段的链接。

Is there anyway I can say, if featured don't display? 如果没有显示,我还能说什么吗?

<?php
// Get the taxonomy
$terms = get_terms('filter');

// set a count to the amount of categories in our taxonomy
$count = count($terms);

// set a count value to 0
$i = 0;

// test if the count has any categories
if ($count > 0) {

    // break each of the categories into individual elements
    foreach ($terms as $term) {

        // increase the count by 1
        $i++;


        $feat = term_exists('featured', 'filter', 'project');
        if ($feat !== 0 && $feat !== null) {
            $feat .= "";
        }



        // rewrite the output for each category
        $term_list .= '<li><a href="javascript:void(0)" class="' . $term->slug . '">' . $term->name . '</a></li>';

        // if count is equal to i then output blank
        if ($count != $i) {
            $term_list .= '';
        } else {
            $term_list .= '';
        }
    }

    // print out each of the categories in our new format
    echo $term_list;
}
?>
               </ul>

I figured out something that managed to work for me: 我发现了一些对我有用的东西:

This: 这个:

$terms = get_terms('filter');

To this: 对此:

$terms = get_terms( 'filter', array(
    'exclude'    => '6'
) );

The 6 being the ID of the slug within my taxonomy. 6是我的分类法中子弹的ID。

Simple excludes one of the categories appearing in the list, meaning no link for someone to click. “简单”排除出现在列表中的类别之一,这意味着没有链接可供某人单击。 Job done. 任务完成。 Hope this might help someone else. 希望这可以帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM