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.

Display category on single entry page

November 15, 2010 6:04pm

Subscribe [4]
  • #1 / Nov 15, 2010 6:04pm

    fouroakschurch

    28 posts

    I’d like to list the categories an entry is posted in. If no categories have been selected, I’d like it to say “None” or not show the category section all together. Using if no_results doesn’t seem to work.

    My code is below (and doesn’t work):

    <strong>Category:</strong> {categories backspace="2"}{if no_results}None{if:else}{category_name}, {/if}{/categories}
  • #2 / Nov 15, 2010 6:46pm

    Wouter Vervloet's avatar

    Wouter Vervloet

    758 posts

    The categories loop doesn’t have a no_results conditional, so that won’t work.

    There is a plugin available for EE1 called Category Count, but it hasn’t been ported to EE2 yet.

    I could check and see if I can whip something up as I don’t think it should be hard to create something for EE2.

    Greetz,
    Wouter

  • #3 / Nov 15, 2010 6:53pm

    fouroakschurch

    28 posts

    Yeah, I’m on EE2. If you wouldn’t mind putting something together real quick, that’d be great!

  • #4 / Nov 15, 2010 7:46pm

    Wouter Vervloet's avatar

    Wouter Vervloet

    758 posts

    As promised, here’s a quick extensions to do what you need and you can get it from GitHub.

    Just install the add-on and it adds a {category_count} variable to the available variables in the {exp:channel:entries} loop.

    {exp:channel:entries channel='lorem'}
      {if category_count == 0}None{if:else}{categories backspace='2'}{category_name}, {/categories}{/if}
    {/exp:channel:entries}

    I haven’t tested it extensively, but this add-on is so simple it couldn’t break that much.

    Greetz,
    Wouter

  • #5 / Nov 15, 2010 7:47pm

    fouroakschurch

    28 posts

    Awesome, thank you!

  • #6 / Nov 15, 2010 7:56pm

    Wouter Vervloet's avatar

    Wouter Vervloet

    758 posts

    Does it work for you?

  • #7 / Nov 16, 2010 8:26am

    Sue Crocker's avatar

    Sue Crocker

    26052 posts

    Thanks for the assist, Wouter!

    fouroakschurch, does Wouter’s add-on help?

  • #8 / Nov 30, 2010 5:08pm

    briankalwat's avatar

    briankalwat

    50 posts

    Working great for me! Thank you so much!

  • #9 / Dec 01, 2010 7:49am

    Sue Crocker's avatar

    Sue Crocker

    26052 posts

    Glad to hear it Brian.

    fouroakschurch, what about you?

ExpressionEngine News

#eecms, #events, #releases