ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Check for Category

September 18, 2009 5:44pm

Subscribe [3]
  • #1 / Sep 18, 2009 5:44pm

    DRUMZ

    75 posts

    Ok, I thought I had this working and it’s probably something simple I’m missing. How do you check to see if a weblog entry has category? I thought by just doing

    {categories}
    {if category_id != ""}
    (do something)
    {if:else}
    (do something else)
    {/if}
    {/categories}

    I’d be fine. Well if there is a category, then the stuff in the first “if” works, but anything inside the {if:else} part doesn’t execute if there’s no category. I want to display the category image if there is a category, and display a default image if there is no category.

    Any help?

  • #2 / Sep 18, 2009 11:39pm

    Herb

    224 posts

    Probable the easiest way to handle this would be:

    <?php $has_categories = "n"; ?>
    {categories}
    do something
    <?php $has_categories = "y"; ?>
    {/categories} 
    <?php if ($has_categories == "n") { ?>
    do something else
    <?php } ?>

    Make sure php enabled on output.  Since php would be on output, every thing between the {categories} and {/categories} will be removed if there is no category; therefor, $has_categories will not be set to “y”.

  • #3 / Sep 20, 2009 3:53am

    Laisvunas

    879 posts

    Hi DRUMZ,

    To check if entry has categories you can use Entry Categories plugin.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases