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.

Ifs not working? Odd

May 20, 2008 12:22pm

Subscribe [2]
  • #1 / May 20, 2008 12:22pm

    briciusaz

    38 posts

    I have been using conditionals for awhile now and they are pretty easy to use but till this morning, it doesnt just work for me anymore. Am i do anything wrong here? Every time I add if photonews- I would lose whole thing but just showing the news without photo. If I remove if and I would get both (that makes sense)... ?

    {if photonews}
     <div id="tabimg">{exp:weblog:entries weblog="default_site" orderby="date" sort="desc" limit="1" show_future_entries="yes" category="1"}{photonews}{/exp:weblog:entries}</div>
     <ul id="tablink">
       <li class="border"><h4>{exp:weblog:entries weblog="default_site" orderby="date" sort="desc" limit="1" show_future_entries="yes" category="1"}{title}</h4><p><span>{entry_date format=' %n/%d/%y '}</span> </li><br />
       <li>{exp:word_limit_plus if_exceeds="10" stop_after="20" the_link="<a href='{title_permalink=hr}'>MORE</a>"}<br />
    {body}{/exp:word_limit_plus}{/exp:weblog:entries}</li><br />
       </ul><br />
     {/if}</p>
    
    <p><br />
     <ul id="tablinkk"><br />
       <li class="border"></p><h4>{exp:weblog:entries weblog="default_site" orderby="date" sort="desc" limit="1" show_future_entries="yes" category="1"}{title}</h4><p><span>{entry_date format=' %n/%d/%y '}</span> </li><br />
       <li>{exp:word_limit_plus if_exceeds="25" stop_after="27" the_link="<a href='{title_permalink=hr}'>MORE</a>"}<br />
    {body}{/exp:word_limit_plus}{/exp:weblog:entries}</li><br />
       </ul>

  • #2 / May 20, 2008 12:28pm

    ImpGabe

    171 posts

    Is photonews a weblog field? If so, then are you calling up the weblog first? Otherwise EE won’t know what photonews is.
    And if you are, you can’t call up exp tags within other exp tags without doing an embed.

  • #3 / May 20, 2008 12:31pm

    briciusaz

    38 posts

    Yes it’s a field name. Like I mentioned it is working if I am not using {if photonews}. Basically if you look at the code, you will see path for (photonews}. The photo shows up there fine. Just that with {if} seems caused this to disappear while showing the alternative entry if there’s no photo. If that’s what you were trying to say, what do you suggest? What would you change based on the coes above?

    Many thanks for the help

  • #4 / May 20, 2008 12:36pm

    ImpGabe

    171 posts

    So you want the whole <ul> to not show up if that field is empty? And are you calling up the same weblogs in both instances of you exp tags? If this is the case then I would just call up the exp tag outside of the if statements.

    If all you want to not show up is the img if there’s no photonews field, then put the if statements on the outside of the img tag.

    The reason it works when you take the if statements away is that when they’re there, EE is looking for a condition to be fulfilled that isn’t going to be since photonews isn’t defined at that point. So nothing shows up at all.

  • #5 / May 20, 2008 12:39pm

    briciusaz

    38 posts

    Basically to show if we have a photo:

    {if photonews}
    Content
    {/if}

    If no photo:

    show the content.

    The main reason for this is because of the CSS I have, I had to create two different css one for photo and one for without. That’s why I am not using the one you suggested

  • #6 / May 20, 2008 12:46pm

    ImpGabe

    171 posts

    Do you understand why your if statement isn’t working?

  • #7 / May 20, 2008 12:47pm

    briciusaz

    38 posts

    appears no. Sorry

  • #8 / May 20, 2008 12:51pm

    ImpGabe

    171 posts

    photonews is a field in the weblog. If you don’t do this :

    {exp:weblog:entries weblog="default_site" orderby="date" sort="desc" limit="1" show_future_entries="yes" category="1"}

    before you do this

    {if photonews}

    then EE will not know what photonews is and will treat it as a variable with no definition. Therefore the if statement won’t ever be satisfied and the content will not show up.  You have to tell EE where photonews is coming from before you can use it in an if statement.

  • #9 / May 20, 2008 1:01pm

    briciusaz

    38 posts

    Aw! Got it! Now I have other plm—when we actually do have a photo- how do I hide a part for one with no photo?

    {exp:weblog:entries weblog="default_site" orderby="date" sort="desc" limit="1" show_future_entries="yes" category="1" dynamic="off"}
    {if photonews}
     <div id="tabimg">{photonews}</div>
     <ul id="tablink">
       <li class="border"><h4>{title}</h4><p><span>{entry_date format=' %n/%d/%y '}</span> </li><br />
       <li>{exp:word_limit_plus if_exceeds="10" stop_after="20" the_link="<a href='{title_permalink=hr}'>MORE</a>"}<br />
    {body}{/exp:word_limit_plus}<br />
    {/if}<br />
     <ul id="tablinkk"><br />
       <li class="border"></p><h4>{title}</h4><p><span>{entry_date format=' %n/%d/%y '}</span> </li><br />
       <li>{exp:word_limit_plus if_exceeds="10" stop_after="20" the_link="<a href='{title_permalink=hr}'>MORE</a>"}<br />
    {body}{/exp:word_limit_plus}</p>
    
    <p>{/exp:weblog:entries}

  • #10 / May 20, 2008 1:04pm

    ImpGabe

    171 posts

    Move your {/if} to right above the {/exp:weblog:entries} and where it is now put {if:else}

  • #11 / May 20, 2008 1:08pm

    briciusaz

    38 posts

    Thank you!

  • #12 / May 20, 2008 1:22pm

    ImpGabe

    171 posts

    Sure. Glad you got it working.

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

ExpressionEngine News!

#eecms, #events, #releases