Wordpress:如果the_category!="category2"

Lin*_*e57 1 php wordpress categories

快速Wordpress问题.是否可以检查特定类别,以便不显示它?我尝试了这个,但我的类别仍然被回应(没有错误).

 <?php if (the_category() != "NAMEOFMYCATEGORY") { the_category(' | '); } ?>
Run Code Online (Sandbox Code Playgroud)

或者我需要使用新功能吗?

澄清:我想隐藏1个特定类别,因此它不显示.

jan*_*anw 8

这应该工作:

<?php
foreach (get_the_category() as $category) {
    if ( $category->name !== 'FORBIDDEN CATEGORY NAME' ) {
        echo '<a href="' . get_category_link($category->term_id) . '">' .$category->name . '</a><br />'; //Markup as you see fit
    }
Run Code Online (Sandbox Code Playgroud)

这个名字是Caps敏感的.