• Hey guys.

    Simply put, I’d like to check if there are any tags or categories applied to a post, if not, I don’t want to display the code that shows categories and/or tags.

    How would I form an if statement that checks for tags and categories (separately)?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • ralph, first off neat question. i payed around and think this works.

    <?php
    if (!has_tag()) {
      echo "";
    }
    else { ?>
    <?php the_tags('Tags: ', ', ', '<br />'); ?>
    <?php } ?>
    <?php
    if (in_category('bananas')) {
      echo "";
    }
    else { ?>
    <?php the_category(', ') ?>
    <?php } ?>

    if it doesn’t have a tag it echo nothing. if it does it prints out the tags.

    the second part checks to see if it’s in a category called bananas (change this to be some category you will never have). If it is it echos nothing else it lists the categories. Not sure if the category part works or not. Can you make a post not in a category at all?

    of course you’ll need to print out what you need this was just using my structure for testing.

    Thread Starter ralph23

    (@ralph23)

    Thanks alot tugbucket. And thats right, duh. You can’t post NOT in a category, wordpress automatically files posts in your default category. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Check if There are Any Tags and/or Categories’ is closed to new replies.