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.

conditional to check if there are assigned categories or not?

July 15, 2012 9:45pm

Subscribe [3]
  • #1 / Jul 15, 2012 9:45pm

    roryrabbitfield

    320 posts

    I am doing a blog and I want to show the categories at the end of the blog text, but only if there are categories assigned to that entry. So, how do I write a conditonal that would test for whethere there are categories or not? I want to wrap the following line of code in that conditonal:

    CATEGORIES:   {categories backspace="2"}<a href="http://{path=blog}">{category_name}</a>, {/categories}

    So, to be clear, I want the line of code above to be used only if there are categories assigned to the entry.

    thanks, Rory

  • #2 / Jul 16, 2012 11:07pm

    roryrabbitfield

    320 posts

    help?

  • #3 / Jul 17, 2012 12:59pm

    Kyle Cotter

    730 posts

    Hey Rory,

    You can use multiple category tags to display the proper content like so:

    {categories limit="1"}CATEGORIES:   {/categories}
    
    {categories backspace="2"}<a href="http://{path=blog}">{category_name}</a>, {/categories}
    
    {categories limit="1"} {/categories}

    In this example, it will only display the paragraph tag and “CATEGORIES:” if there is at least 1 category.

    If you feel this out of the box solution is too clunky, you can try using BW Category Count to conditionally display your text.

    Does that help?

    Thanks!

  • #4 / Jul 17, 2012 1:26pm

    roryrabbitfield

    320 posts

    I think this solution will work just fine! I won’t know for sure till I try it out tonight. But this suits my needs. Thanks!

  • #5 / Jul 17, 2012 1:58pm

    Kyle Cotter

    730 posts

    Glad to hear it Rory! I’ll leave this thread open until you’re able to report back on if it works for you.

    Thanks!

  • #6 / Jul 17, 2012 10:31pm

    roryrabbitfield

    320 posts

    Well that worked perfectly! Thanks again. Case closed.

  • #7 / Jul 18, 2012 10:03am

    Kyle Cotter

    730 posts

    Great! If you have any more questions, feel free to start a new thread.

    Thanks!

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

ExpressionEngine News!

#eecms, #events, #releases