Wordpress: If the_category != "category2"

Quick Wordpress question. Is it possible to check against a specific category, so not to display it? I tried this, but my category was still being echoed (no errors).

 <?php if (the_category() != "NAMEOFMYCATEGORY") { the_category(' | '); } ?>

Or would I need to work with a new function?

To clarify: I want to HIDE 1 specific category so it doesn't show up.

Answers


This should work:

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

The name is Caps sensitive.


Why not to use the codex version?

if (is_home()) {query_posts('cat=-1,-2,-3'); }  // excludes categories 1 2 3

also do you remember in_category() ?

if (have_posts() && (!in_category('3')) {

//do domething;

} else // do different loop

I think you need to do something like this, if i got ur question correctly :)

foreach((get_the_category()) as $category) {
   if($category->cat_name = 'mycheckcatname')
   {
   DO THIS
   }
   else
   {
   Do THAT
   }
}

NEW EDIT--

or this is what else u are looking for ---

<?php if (is_category('Category A')) : ?>
<p>This is the text to describe category A</p>
<?php elseif (is_category('Category B')) : ?>
<p>This is the text to describe category B</p>
<?php else : ?>
<p>This is some generic text to describe all other category pages, 
I could be left blank</p>
<?php endif; ?>

Need Your Help

How to send a curl request with pem certificate via PHP?

php apache api ssl curl

I have a php script in my Apache server that have to send a curl request to a partner's server.