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.

Showing template content based on category

September 14, 2010 12:01am

Subscribe [2]
  • #1 / Sep 14, 2010 12:01am

    jsuissa

    147 posts

    Hello,

    I cannot figure out how to display a part of a template only for an entry that falls under a certain category(s).

    Any help with an example of a conditional I would use to show a line of HTML if an entry was classified under say categories 3 or 6, would be great.

    Thanks for you help in advance.

  • #2 / Sep 14, 2010 3:17am

    ralph.m

    225 posts

    If you have categories set up for a channel, each category will have a number, which you specify like so:

    {exp:channel:entries channel="channel-name" disable="trackbacks|member_data|pagination" category=“8” sort=“desc” dynamic=“no”}

    Does that make sense?

    EDIT: Hmm, I suspect this was not what you were asking. Could you rephrase the question a little, by giving an example?

  • #3 / Sep 14, 2010 9:39am

    jsuissa

    147 posts

    Thanks for the reply.

    Hopefully, this will help clarify.

    What I’m looking to do is if an entry is in category 3 or 6 display Size:{size}, but if they’re not in either of those categories I don’t want it to appear.

    Thanks in advance.

  • #4 / Sep 14, 2010 10:26am

    ralph.m

    225 posts

    From what I can tell, no. Well, I don’t think there’s a conditional for that. You’d want something like

    {if category=="3|6"}
        Size:{size}
    {/if}

    but that doesn’t exist.

    Two questions: Can any category appear on your page? Or does only one category appear per page…. since then you could do what I showed above.

    If any category can appear on the one page, is there size info set for categories other than 3 and 6? If not, of course, you would just use

    {if size}
        Size:{size}
    {/if}
  • #5 / Sep 14, 2010 10:43am

    jsuissa

    147 posts

    From that category group in question there can only be one category per page from say 2,3,4,5,6 but there is another category group used say it’s called…7,8,9 that also appears on the page.

    Size is a text field—so would {if size} work if the user just left the text field blank then it won’t show up and if it’s filled in the {size} shows as a conditional statement?

    Thanks!

  • #6 / Sep 14, 2010 10:56am

    ralph.m

    225 posts

    Size is a text field—so would {if size} work if the user just left the text field blank then it won’t show up and if it’s filled in the {size} shows as a conditional statement?

    That’s my understanding, yes. Just leave it blank if the info isn’t wanted. Of course, make sure to set it as an optional field.

  • #7 / Sep 14, 2010 11:10am

    jsuissa

    147 posts

    That worked out well. Thanks!

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

ExpressionEngine News!

#eecms, #events, #releases