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 elseif question

June 23, 2011 5:02pm

Subscribe [2]
  • #1 / Jun 23, 2011 5:02pm

    dodgson

    120 posts

    I have a site that has a public side and a member side. Each side of the site has its own news section. The only difference is that members can also read the public news. not vice versa.

    I’m trying to find a way to show the news articles for both the public and member sections if a user is a logged in member. I have it working except for the permalink. I don’t know how to get it to show the members permalink.

    Any help would be greatly appreciated.

    {if logged_in}
                        
        {exp:channel:entries channel="news_members|news_public" limit="3"}
                            
        <h2>{title}</h2>
    <p>    <br />
            {exp:word_limit total="20"}<br />
            {public_news_body}<br />
            {member_news_body}<br />
        {/exp:word_limit}<br />
                                <br />
        <a href="http://{title_permalink=">Continue Reading</a><br />
                            <br />
        {/exp:channel:entries}<br />
                    <br />
    {if:else}<br />
                    <br />
        {exp:channel:entries channel="news_public" limit="3"}<br />
                            <br />
        </p><h2>{title}</h2>
    <p>    <br />
            {exp:word_limit total="20"}<br />
            {public_news_body}<br />
        {/exp:word_limit}<br />
                                <br />
        <a href="http://{title_permalink=">Continue Reading</a><br />
                            <br />
        {/exp:channel:entries}<br />
                    <br />
    {/if}

  • #2 / Jun 23, 2011 5:09pm

    Rob Allen

    3118 posts

    You need to add the template group and template names to the link

    <a permalink='templategroup/template'>Continue Reading</a>

    So if your template group was called “news” and your single entry template was called “article” the link would be…

    <a permalink='news/article'>Continue Reading</a>
  • #3 / Jun 23, 2011 5:11pm

    Mark Bowen

    12637 posts

    Hiya,

    I think the forums may have stripped out some of your code here, specifically the title_permalink parts. That said I’m not too sure what the problem is here except for you may be having problems due to trying to use an {if:else} structure within the {if logged_in} conditional which I’m fairly certain doesn’t work.

    You will need to have two conditionals here :

    {if logged_in}
        {exp:channel:entries channel="news_members|news_public" limit="3"}
                            
        <h2>{title}</h2>
    <p>    <br />
            {exp:word_limit total="20"}<br />
            {public_news_body}<br />
            {member_news_body}<br />
        {/exp:word_limit}<br />
                                <br />
        <a href="http://{title_permalink=template_group/template}">Continue Reading</a><br />
                            <br />
        {/exp:channel:entries}<br />
    {/if}</p>
    
    <p>{if logged_out}<br />
        {exp:channel:entries channel="news_public" limit="3"}<br />
                            <br />
        </p><h2>{title}</h2>
    <p>    <br />
            {exp:word_limit total="20"}<br />
            {public_news_body}<br />
        {/exp:word_limit}<br />
                                <br />
        <a href="http://{title_permalink=template_group/template}">Continue Reading</a><br />
                            <br />
        {/exp:channel:entries}<br />
    {/if}

    Hope that helps a bit.

    Best wishes,

    Mark

  • #4 / Jun 23, 2011 5:26pm

    dodgson

    120 posts

    LOL. Yes it did strip out the template paths. The problem that I’m having is with the “If Logged_in” statement. I’m currently showing the “public_news_body’ if it’s public news and I’m showing the member_news_body if it’s member news. The problem is with the permalink. I’m not sure how to have 1 permalink that would work for both the public side which has it’s own template page and the members side which has it’s own template page.

    Is this an incorrect way to set this up. I hope that made sense. I’m confusing myself. Thanks for the help guys.

  • #5 / Jun 23, 2011 5:56pm

    Rob Allen

    3118 posts

    Do you have one template for a single news entry or two templates (one for public, one for private)? You could do it using one template using some more conditionals, or just use two template sto make it easier.

    If you’re using two templates for single entry page you could add another conditional that checking which Channel the entry is from…

    {if channel == "news_members"}
    <a permalink='template_group/member_template'>Continue Reading</a>
    {/if}
    {if channel == "news_public"}
    <a permalink='template_group/public_template'>Continue Reading</a>
    {/if}
  • #6 / Jun 23, 2011 6:15pm

    dodgson

    120 posts

    That’s brilliant. Thank you so much for the help. That will work perfectly.

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

ExpressionEngine News!

#eecms, #events, #releases