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.

{if categories} blah {/if} <-- should this work, am I doing something wrong?

February 25, 2011 12:56pm

Subscribe [3]
  • #1 / Feb 25, 2011 12:56pm

    TGP

    78 posts

    I have some code to display a list of categories assigned to a blog post. I don’t want any of it to appear if there are no categories assigned to the blog post. Tried putting an if statement around it and it didn’t show up at all, even when a category was assigned. is this possible and if it is, what am I doing wrong? Thanks!

    {if categories}Categories: {categories backspace="1"} <a href="http://{path=driving-your-success}" title="{category_name}">{category_name}</a>,{/categories}{/if}
  • #2 / Feb 25, 2011 4:45pm

    Barry Cogan

    291 posts

    Hi TPG,

    Does the example below work for you the way you want?

    {categories}<a href="#">{category_name}</a> {/categories}

    That should show only the categories for the post so long as they are inside the {exp:channel:entries}{/exp:channel:entries} tag pair.
    Categories should not appear if there are none.  There should be no need for the {if categories}

    Best regards,
    Barry

  • #3 / Mar 13, 2011 7:19pm

    John Henry Donovan

    12339 posts

    TGP,

    Let us know if that works for you. To make it more like what you want here is the full example incorporating your code

    Categories: {categories backspace="1"}<a href="http://{path=driving-your-success}" title="{category_name}">{category_name}</a>,{/categories}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases