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.

Looking for help with conditional stmt and viewing articles with draft status

February 10, 2011 10:21pm

Subscribe [7]
  • #16 / Feb 22, 2011 3:08pm

    JulesWebb

    271 posts

    I removed the embeds and place minimal code within the conditional statement. (see code below)  I was still redirected to the 404 page.

    I played around with it and even if I remove the {if no_results}{redirect="site/404"}{/if} from the if logged in section I’m still redirected.  If I remove it from both sections it works, BUT then page (minus the article) still loads for the logged out user.  This doesn’t seem right to me.

    What are your thoughts now?

    {if logged_in_group_id == 1 || logged_in_group_id == 6  } 
    
    <!-- =========================================================== -->    
    <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
    <!-- =========================================================== --> 
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Announcement|Open|Draft" status="not Closed" require_entry="yes" url_title="{segment_3}"}
    {if no_results}{redirect="site/404"}{/if}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />   
    </head>
    {/exp:weblog:entries}
    
    {/if}            
    {if logged_out}
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Open|Announcement" status="not Closed|Draft" require_entry="yes" url_title="{segment_3}"}
    
    {if no_results}{redirect="site/404"}{/if}
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}
  • #17 / Feb 23, 2011 6:31am

    John Henry Donovan

    12339 posts

    You still have multiple status parameters in your weblog entry tags

    status="Announcement|Open|Draft" status="not Closed"

    using all our suggestions from above do the following

    {if group_id == '1' || group_id == '6'  } 
    
    <!-- =========================================================== -->    
    <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
    <!-- =========================================================== --> 
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination"  status="not closed" url_title="{segment_3}"}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />   
    </head>
    {/exp:weblog:entries}
    
    {/if}            
    {if logged_out}
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="not closed|Draft" url_title="{segment_3}"}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}
  • #18 / Feb 23, 2011 11:01pm

    JulesWebb

    271 posts

    Hi John

    Yes that does work, but like I said in my previous post, without the redirect for logged out users the page will still show up in an unacceptable manner (it just doesn’t have the article included on the page).  If I add {if no_results}{redirect="site/404"}{/if} to the {if logged_out} section of the code you presented I get redirected even when I’m logged in as the admin. 

    Jules

  • #19 / Feb 24, 2011 12:17pm

    Barry Cogan

    291 posts

    Hi Jules,

    John’s post does have the logged out redirect in his example above. 

    {if logged_out}
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="not closed|Draft" url_title="{segment_3}" require_entry="yes"}
    
    {if no_results}
        {redirect=“site/404”}
    {/if}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}

    Does this logged out section behave for you? I added the require entry and put no_results conditional in a place where it should not be triggering when logged in as admin.

    Best regards,
    Barry

  • #20 / Feb 25, 2011 7:34pm

    JulesWebb

    271 posts

    John’s post does have the logged out redirect in his example above.

    Look again Barry.  Thinking my eyes were deceiving me I did a control “f” and highlighted all “if no_results” and I still didn’t see any in John Henry Donovan post.

    Does this logged out section behave for you? I added the require entry and put no_results conditional in a place where it should not be triggering when logged in as admin.

    I’m assuming I was still suppose to use {if logged_in_group_id == 1 || logged_in_group_id == 6 } section.  Below is the code I used and I still get the same results.  If I remove the {if no_results} condition it will work, but then the page will load for logged out members, just not the article.

    Did I do what you wanted me to?

    I appreciate everyone’s continued help and patience with this issue, thanks:)

    {if logged_in_group_id == 1 || logged_in_group_id == 6  } 
    
    <!-- =========================================================== -->    
    <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
    <!-- =========================================================== --> 
    
        {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Announcement|Open|Draft" status="not Closed" require_entry="yes" url_title="{segment_3}"}
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}            
    {if logged_out}
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="not closed|Draft" url_title="{segment_3}" require_entry="yes"}
    
    {if no_results}
        {redirect="site/404"}
    {/if}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}
  • #21 / Feb 27, 2011 4:11pm

    Greg Salt

    3988 posts

    Hi Jules,

    Please try splitting up the first conditional:

    {if group_id == 1}
    {if group_id == 6} 
    
    <!-- =========================================================== -->    
    <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
    <!-- =========================================================== --> 
    
        {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Announcement|Open|Draft" status="not Closed" require_entry="yes" url_title="{segment_3}"}
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}
    {/if}     
         
    {if logged_out}
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="not closed|Draft" url_title="{segment_3}" require_entry="yes"}
    
    {if no_results}
        {redirect="site/404"}
    {/if}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}

    Cheers

    Greg

  • #22 / Feb 27, 2011 7:06pm

    JulesWebb

    271 posts

    Hi Greg

    I got the same results. I’ve also tried setting the condition to just the admin {if logged_in_group_id == 1} and that doesn’t work either.  Is there anyway I can send the code form the whole page?  Though I’ve gone over and over it, I may be missing something.

    Jules

  • #23 / Feb 28, 2011 8:55am

    Sue Crocker

    26054 posts

    Hi, Jules. Do you mean use a different embed depending on the group_id?

  • #24 / Feb 28, 2011 1:34pm

    JulesWebb

    271 posts

    Hi Sue,

    Not sure what you are asking.  I’ve been using the condition

    {if logged_in_group_id == 1 || logged_in_group_id == 6  }

    and

    {if logged_out}

    The embed is the same for both.  The only difference between the two are the statuses requested.

    Jules

  • #25 / Mar 01, 2011 3:19am

    John Henry Donovan

    12339 posts

    WebbDiva,

    Not sure what you are asking.  I’ve been using the condition

    {if logged_in_group_id == 1 || logged_in_group_id == 6  }

    Did you try the other ones like I asked you too?

    {if group_id == '1' || group_id == '6'  }

    You still have multiple status parameters in your weblog entry tags

    status="Announcement|Open|Draft" status="not Closed"

    Test without the no_results conditional as I suggested here. Use all of my code not just different pieces

    If I remove the {if no_results} condition it will work, but then the page will load for logged out members, just not the article.

    This is what we want to troubleshoot first. Not the implementation of the no_results conditional.

  • #26 / Mar 01, 2011 4:30am

    JulesWebb

    271 posts

    Hi Greg

    I’ve copied and pasted the all the code that’s been presented. Sorry for not clearly communicating that. I’ve also tried at least a hundred variations of my own.

    You still have multiple status parameters in your weblog entry tags

    I’ve tested with and without status parmeters.  I’ve stripped it down to all but {exp:weblog:entries weblog="equine-news" limit="1" } and as long as the redirect is there (for logged out users) it doesn’t work

    Test without the no_results conditional as I suggested here. Use all of my code not just different pieces

    Sorry I wasn’t clear, I did try it with just {if group_id == '1' || group_id == '6' } and yes it works, but again if you add no results to the logged out users it no longer works. Again to be clear, I copied and pasted the code you presented.  Just to be sure I tested it again tonight.

    I hope this helps, sorry for any confusion.

    Jules

  • #27 / Mar 02, 2011 7:26am

    John Henry Donovan

    12339 posts

    Jules ,

    Sorry I wasn’t clear, I did try it with just {if group_id == ‘1’ || group_id == ‘6’ } and yes it works, but again if you add no results to the logged out users it no longer works. Again to be clear, I copied and pasted the code you presented.  Just to be sure I tested it again tonight.

    Ok. Sorry it’s getting confusing. That’s what we wanted to establish. That the conditionals work for you without the redirect in place.

    Now your issue is with parse order.

    Simple conditionals parse in your template before advanced conditionals

    The {if no_results} and {if logged_out} are simple conditionals

    {if group_id == '1' || group_id == '6' } is an advanced conditional


    So can you for now make your opening opening condition a simple one with just


    {if group_id == '1'} or even {if logged_in}

    Let us know if that works for you

    EE Docs : Conditional Global Variables
    PDF : ExpressionEngine’s Parse Order

  • #28 / Mar 03, 2011 2:13am

    ECKwa

    16 posts

    Hi John

    Thanks for the explanation.  I did as you requested and was still sent to the 404 page. 

    Just to be sure you know what code I used I pasted it below.  I also tested with {if group_id == '1'}

    Thanks for hanging in there with me:)
    Jules

    {if logged_in}
    
    <!-- =========================================================== -->    
    <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
    <!-- =========================================================== --> 
    
        {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Announcement|Open|Draft" status="not Closed" require_entry="yes" url_title="{segment_3}"}
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    
    {/if}     
         
    {if logged_out}
    
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="not closed|Draft" url_title="{segment_3}" require_entry="yes"}
    
    {if no_results}
        {redirect="site/404"}
    {/if}
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    {/exp:weblog:entries}
    
    {/if}
  • #29 / Mar 03, 2011 9:32am

    Sue Crocker

    26054 posts

    Why are you even calling the first exp:weblog:entries loop? You aren’t using it for anything practical.

    Here’s what I’d try:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/reset.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/960.css" />
    <link rel="stylesheet" type="text/css" media="screen,projection" href="/memanager/templates/css/style.css" />
       
    </head>
    
    <body>
    {if logged_in}
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|paginate" status="not closed" require_entry="yes"}
    {if no_results}
    {redirect="404"}
    {/if}
    
    You're logged in, and there is an entry!
    {/exp:weblog:entries}
    
    {/if}
    
    {if logged_out}
    {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|paginate" status="Announcement|open" require_entry="yes"}
    {if no_results}
    {redirect="404"}
    {/if}
    You're logged out, and there is an entry!
    
    {/exp:weblog:entries}
    {/if}
    </body>
    </html>
  • #30 / Mar 03, 2011 1:01pm

    JulesWebb

    271 posts

    Hi Sue

    Below is the code that I’m trying to get to work.  I removed the embed as requested for the troubleshooting process and I’m using the exp:weblog:entries loop to bring in the categories and title for the meta data.

    {if logged_in_group_id == 1 || logged_in_group_id == 6  } 
    
    <!-- =========================================================== -->    
    <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
    <!-- =========================================================== --> 
    
        {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Announcement|Open|Draft" status="not Closed" require_entry="yes" url_title="{segment_3}"}
        {if no_results}{redirect="site/404"}{/if}
        {embed="includes/DOC-head" url_title="{segment_3}" 
            title_prefix=""
            title_suffix="{categories show="not 6" backspace="1" limit="2"}{category_name} |{/categories}" 
            hide_site_title="n"
         }
        {/exp:weblog:entries}
    
    {/if}            
    {if logged_out}
    
        {exp:weblog:entries weblog="equine-news" limit="1" disable="member_data|comments|trackbacks|pagination" status="Open|Announcement" status="not Closed|Draft" require_entry="yes" url_title="{segment_3}"}
        {if no_results}{redirect="site/404"}{/if}
        {embed="includes/DOC-head" url_title="{segment_3}" 
            title_prefix=""
            title_suffix="{categories show="not 6" backspace="1" limit="2"}{category_name} |{/categories}" 
            hide_site_title="n"
         }
        {/exp:weblog:entries}
    
    {/if}

    Lower on the page I have the same conditional statement around the article I’m trying to bring in. (code below)

    Do you still want me to test your code?

    {if logged_in_group_id == 1 || logged_in_group_id == 6  } 
    
        <!-- =========================================================== -->    
        <!-- !        ARTICLES LISTED IF SUPER ADMIN OR MANAGER          -->
        <!-- =========================================================== -->  
        {exp:weblog:entries weblog="equine-news" limit="1" status="Announcement|Open|Draft" status="not Closed" disable="member_data|pagination" }   
            
            <div class="postheader clearfix">
                <span class="date"><strong>{entry_date format="%M"}</strong>{entry_date format="%j"} <small>{entry_date format="%Y"}</small></span>
                <h3 class="title-post"><a href="http://{title_permalink=">{exp:xml_encode}{title}{/exp:xml_encode}</a></h3>
                <h4 class="author-post clearfix">               
                    <span class="trans-none floatleft">By </span>
                    <span class="floatleft">{author} </span>
                    <span class="trans-none floatleft"> | Category(s):</span>
                    <span class="categories floatleft">{categories show="not 6" limit="2"}<a href="http://{path=">{category_name}</a> <br>{/categories}</span>                              
                </h4>
            </div><!-- /postheader -->     
            
            {article-body}
            
        {/exp:weblog:entries}                
        
        
    {/if}
    
    
    {if logged_out}    
                      
    
        {exp:weblog:entries weblog="equine-news" limit="1" status="Announcement|Open" disable="member_data|pagination" }
            
            
            <div class="postheader clearfix">
                <span class="date"><strong>{entry_date format="%M"}</strong>{entry_date format="%j"} <small>{entry_date format="%Y"}</small></span>
                <h3 class="title-post"><a href="http://{title_permalink=">{exp:xml_encode}{title}{/exp:xml_encode}</a></h3>
                <h4 class="author-post clearfix">               
                    <span class="trans-none floatleft">By </span>
                    <span class="floatleft">{author} </span>
                    <span class="trans-none floatleft"> | Category(s):</span>
                    <span class="categories floatleft">{categories show="not 6" limit="2"}<a href="http://{path=">{category_name}</a> <br>{/categories}</span>                              
                </h4>
            </div><!-- /postheader -->               
            
            
            {article-body}
            
        {/exp:weblog:entries}
        
     {/if}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases