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 conditional with category_id

November 09, 2011 1:20pm

Subscribe [3]
  • #1 / Nov 09, 2011 1:20pm

    kate1975

    11 posts

    Hi, I’m trying to call a form in a snippet called {share_your_story} only for a specific entry on a template. This is the code I’m using and the form doesn’t show up even if that’s the category id of my entry. Without the if conditional the form shows up on all my entries of this specific template.

    {if category_id == "64"}
    {share_your_story}
    {/if}

    Any ideas?

  • #2 / Nov 09, 2011 2:21pm

    grantmx

    1439 posts

    You can either use the cat_id in the url as a segment variable or you have to be more specific with the cat_id tag:

    {if '{category_id}' == “64”}
    {share_your_story}
    {/if}
  • #3 / Nov 09, 2011 3:28pm

    kate1975

    11 posts

    I already tried that way and it still doesn’t work. I don’t know how to do the cat_id in the url as a segment variable that you mentioned either.

  • #4 / Nov 09, 2011 4:03pm

    Mark Bowen

    12637 posts

    Where do you have your {if} statement?

    It will need to be inside a main tag in order for the category_id part to mean anything to it.

    Can you share some more of your code here.

    Best wishes,

    Mark

  • #5 / Nov 09, 2011 4:24pm

    kate1975

    11 posts

    This is more code around the category_id.

    {exp:channel:entries channel="site" dynamic="yes"  limit="1"  require_entry="yes"}
       {if no_results}
    
            {redirect="404"}
    
        {/if}
    <h2>Who</h2>
    <h4>{title}</h4>
    
    <p>{exp:pagination paginate="bottom"}</p>
    
    <p>{body}</p>
    
    <p>{if '{category_id}' == "64"}<br />
    {share_your_story}<br />
    {/if}</p>
    
    <p>{extended}</p>
    
    <p>{simplepaginate}</p>
    
    <p><div id="pagination"><br />
     {all_pagination_links}<br />
    </div></p>
    
    <p>{/simplepaginate}<br />
    {/exp:pagination} </p>
    
    <p>{/exp:channel:entries}

  • #6 / Nov 09, 2011 4:37pm

    Mark Bowen

    12637 posts

    What exactly is {exp:pagination}?

    Is that a 3rd party add-on maybe?

    If so then that won’t be supported here and you’d need to go to the developer with any problems with that although you don’t have the required {categories} pair around your code so it’s never going to work.

    If you do this does it work?

    {exp:channel:entries channel="site" dynamic="yes"  limit="1"  require_entry="yes"}
       {if no_results}
    
            {redirect="404"}
    
        {/if}
    <h2>Who</h2>
    <h4>{title}</h4>
    
    <p>{exp:pagination paginate="bottom"}</p>
    
    <p>{body}</p>
    
    <p>{categories}<br />
    {if category_id == "64"}<br />
    {share_your_story}<br />
    {/if}<br />
    {/categories}<br />
    {extended}</p>
    
    <p>{simplepaginate}</p>
    
    <p><div id="pagination"><br />
     {all_pagination_links}<br />
    </div></p>
    
    <p>{/simplepaginate}<br />
    {/exp:pagination} </p>
    
    <p>{/exp:channel:entries}

    If not then try this instead :

    {exp:channel:entries channel="site" dynamic="yes"  limit="1"  require_entry="yes"}
       {if no_results}
    
            {redirect="404"}
    
        {/if}
    <h2>Who</h2>
    <h4>{title}</h4>
    
    <p>{categories}<br />
    {if category_id == "64"}<br />
    {share_your_story}<br />
    {/if}<br />
    {/categories}</p>
    
    <p>{exp:pagination paginate="bottom"}</p>
    
    <p>{body}</p>
    
    <p>{extended}</p>
    
    <p>{simplepaginate}</p>
    
    <p><div id="pagination"><br />
     {all_pagination_links}<br />
    </div></p>
    
    <p>{/simplepaginate}<br />
    {/exp:pagination} </p>
    
    <p>{/exp:channel:entries}

    One of those should hopefully work for you. Also I noticed that you have your {body} field inside the pagination tags which is a little odd. Any reason for doing things in this way?

    Best wishes,

    Mark

     

  • #7 / Nov 09, 2011 4:53pm

    kate1975

    11 posts

    Thank you sooooo much! The first option worked great.

    http://www.drinkyourcarbs.com/site/who/contact_us

    {exp:pagination paginate="bottom"} and {simplepaginate} break the pages into bite size text. It works the way I have it and that’s about as much as I know 😉

    Example:http://www.drinkyourcarbs.com/site/who/who

  • #8 / Nov 09, 2011 4:55pm

    Mark Bowen

    12637 posts

    Excellent news! Glad that got you sorted there.

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases