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 for displaying category info in a post

November 05, 2008 12:38pm

Subscribe [2]
  • #1 / Nov 05, 2008 12:38pm

    secondlamppost

    22 posts

    This question may be related to a resolved thread.

    I am trying to create something very similar to the thread above. In each post on the page I would like to have a conditional that shows “Posted in CATEGORY” only if there is an associated category. But I cannot find a conditional variable in Global or Weblog conditionals that allow me to target the presence of categories. If one exists my code would look something like this:

    {if category_name != ""}
        Posted in 
        {categories}
        <a href="http://{path={my_weblog}categories}">{category_name}</a>
        {/categories}
        
    {/if}

    How can I work around this to target categories assigned to each post?

  • #2 / Nov 05, 2008 1:10pm

    Robin Sowell

    13255 posts

    What happens when you try the code in the posted thread- though you’ll want to remove the group_id parameter.  So something like

    {categories limit="1"}
    Posted in:
    
    {/categories}
    {categories backspace="1"}
              ♦ {category_name},
    {/categories}

    That assumes you can have more than one category assigned to an entry.  If you only every have one category, you could just do:

    {categories}
              Posted in: {category_name}
    {/categories}
  • #3 / Nov 05, 2008 2:36pm

    secondlamppost

    22 posts

    Ah, great idea using {categories limit="1"} for the “Posted in:” portion of the list. That worked perfectly. Thanks Robin.

  • #4 / Nov 05, 2008 5:30pm

    Ingmar

    29245 posts

    Glad to see Robin squared you away there. Please don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases