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 entries conditional query

August 29, 2011 5:57pm

Subscribe [3]
  • #1 / Aug 29, 2011 5:57pm

    stevo_s

    176 posts

    Hi, trying to just list entries by an author on a sidebar only if they have them. I think I am doing the if statement wrong - any ideas?

    {if title}
    blog entries by {firstname}
    
    {exp:channel:entries channel="blog" username="{segment_3}" limit="3" orderby="date" dynamic="no"}
    <a href="http://{title_permalink=blog/entry}">{title}</a>
    
    {/exp:channel:entries}
    {/if}
  • #2 / Aug 30, 2011 1:14am

    Dan Decker

    7338 posts

    stevo-s,

    Let’s see if we can get this sorted out. Your conditional should go inside the {exp:channel:entries}{/exp:channel:entries} and you can check for results:

    {exp:channel:entries channel="blog" username="{segment_3}" limit="3" orderby="date" dynamic="no"}
    {if no results}
    no results content
    {if:else}
    {title}
    blog entries by {firstname}
    
    <a href="http://{title_permalink=blog/entry}">{title}</a>
    
    {/if}
    {/exp:channel:entries}

    Let us know if you have any further questions.

    Cheers,

  • #3 / Aug 30, 2011 8:25am

    stevo_s

    176 posts

    Thanks Dan - getting this error though -

    Parse error: syntax error, unexpected T_STRING 
    
    libraries/Functions.php(656) : eval()'d code on line 52
  • #4 / Aug 30, 2011 8:42am

    stevo_s

    176 posts

    I think that should have been {if no_results} ?
    fixes the parse error but it still doesn’t show the no results or results message though -just blank.

    should there be a second if statement ?

  • #5 / Aug 30, 2011 7:34pm

    stevo_s

    176 posts

    anyone ideas why this wouldn’t work?

    {exp:channel:entries channel="blog" username="{segment_3}" limit="3" orderby="date" dynamic="no"}
    {if no_results}
    no results
    {if:else}
    Blog entries by {firstname}
    
    <a href="http://{title_permalink=blog/entry}">{title}</a>
    {/if}
    {/exp:channel:entries}
  • #6 / Aug 30, 2011 8:23pm

    stevo_s

    176 posts

    If I remove the if statement altogether for some reason it works ok and doesn’t print the ‘blog entries by ’ text if there are no entries for a page - weird - is the entire page badly done?

    here’s the code of the page:

    <div id="page">
    <div id="content_wrapper">
    
    {exp:channel:entries channel="portfolios" username="{segment_3}" limit="1"}
    <h3>{firstname} {surname}<h3>
    
    {/exp:channel:entries}
    
    {exp:channel:entries channel="portfolios" orderby="date" dynamic="off" username="{segment_3}" sort="desc"  limit="6"}
    {thumbnail}{path}_thumb_folio/{filename}.{extension}{/thumbnail}
    {paginate} Page {current_page} of {total_pages} pages {pagination_links}{/paginate}
    {/exp:channel:entries}
    
    
    <div id="sidebar">
    {exp:channel:entries channel="portfolios" dynamic="off" username="{segment_3}"  limit="1"}
    {if avatar}{avatar_url}{/if}
    {firstname} {surname} 
    
    {if bio}{bio} 
    {/if}
    {if address}{address} 
    {/if}
    {if mobile}{mobile}
    {/if}
    {if twitter}<a href="http://twitter.com/{twitter}">twitter</a>
    {/if}
    {if facebook}<a href="http://www.facebook.com/{facebook}">facebook</a>
    {/if}
    <a href="mailto:{email}">email</a> 
    
    {if url}<a href="http://{url}">Website</a>
    {/if}
    {/exp:channel:entries}
    
    {exp:channel:entries channel="blog" username="{segment_3}" limit="5" orderby="date" dynamic="no"}
    blog entries by {firstname}: 
    
    <a href="http://{title_permalink=blog/entry}">{title}</a>
    {/exp:channel:entries}
    </div>
    
    </div> 
    </div>
  • #7 / Aug 31, 2011 8:11am

    stevo_s

    176 posts

    Does this code look ok or is the no results formatted wrong?

  • #8 / Aug 31, 2011 9:11am

    Dave @ Exp:resso

    465 posts

    Hi Stevo,

    When using no_results its best (from what I’ve read at least) to just have {if no_results}no results message here{/if} - so avoid the if:else here, its not necessary

    It looks like 2 of your channel entries loops could be replaced by one, something like this:

    {exp:channel:entries channel="portfolios" username="{segment_3}" orderby="date" dynamic="off" sort="desc"  limit="6"}
       {if count == 1} // this returns true only for the first entry, hence only repeats this once
         <h3>{firstname} {surname}<h3>
       {/if}
       {thumbnail}{path}_thumb_folio/{filename}.{extension}{/thumbnail} // looks like a strange write the path
       {paginate} Page {current_page} of {total_pages} pages {pagination_links}{/paginate}
       {if no_results}
          No results
       {/if}
    {/exp:channel:entries}
    
    <div id="sidebar">
       {exp:channel:entries channel="portfolios" username="{segment_3}"  dynamic="off" limit="1"}
         Member fields here
       {/exp:channel:entries}
       Blog  code here
    </div>

    Also note the path to the image looks a bit odd… is this using an addon or something? And if you’re trying to do anything remotely custom with member data you’d be better off using solspace user. Seems a bit strange using a channel entries loop just to pull member data in the sidebar, you could try {exp:member:custom_profile_data} if you have the member ID.

    ANyway hope this helps!

  • #9 / Aug 31, 2011 9:39am

    stevo_s

    176 posts

    thanks dave, yes - using CE image for the images. That’s not the full code.

    you could try {exp:member:custom_profile_data} if you have the member ID.

    Tried that but it didn’t work at all. Maybe I need a better example, what was in the user-guide didn’t work anyway. Couldn’t figure out how to get the id.

  • #10 / Aug 31, 2011 9:52am

    Dave @ Exp:resso

    465 posts

    Well firstly, try your initial code with the no results code I suggested (without the {if:else}). You cant have an if:else in a no results tag as far as I know, since its not really a conditional, its just a string that gets replaced with something if theres no results.

    For anything member-related like this I’d suggest solspace user. Its rather annoying how little flexiblity you get with member templates by default in EE. A problem that has no doubt made Solspace a LOT of money.

    {exp:member:custom_profile_data} should work if you use it right, add the member_id=”{segment_3}” param (assuming you can pass through the ID in the url).

  • #11 / Aug 31, 2011 10:15am

    stevo_s

    176 posts

    Yep - removing the if:else seems to do the trick - thanks

    {exp:channel:entries channel="blog" username="{segment_3}" limit="5" orderby="date" dynamic="no"}
    {if no_results}
    no results
    {/if}
    blog entries by {firstname}
    
    <a href="http://{title_permalink=blog/entry}">{title}</a>
    {/exp:channel:entries}


    I don’t think I need solspace users as it is really through the CP I need authors to do everything - entries, email etc.,
    I don’t have any other signed up members apart from a core of about 60. It would help If I could remove fields I don’t need like ICQ, birthdays etc., but I’ll just have to live with it.

    the profile fields work ok in channel:entries I was told in a previous post? certainly seems to be fine.

    Tried this code but it produces nothing. Tried puttin in 1, 2 in member_id or other and that didn’t work either.

    {exp:member:custom_profile_data member_id="{segment_3}"}    
    {firstname} {surname} 
    
    {if bio}{bio} 
    {/if}
    {if address}{address} 
    {/if}
    {if mobile}{mobile}
    {/if}
    {/exp:member:custom_profile_data}
  • #12 / Aug 31, 2011 10:25am

    Dave @ Exp:resso

    465 posts

    GLad the if:else worked! Re the custom_profile_data tag, if it doesn’t work according to the docs here - http://ellislab.com/expressionengine/user-guide/modules/member/custom_profile_data.html - then it could be a bug. And yep the profile fields work in the channel entries loop, just seems wrong having to use channel:entries just for user data. Still works though.

  • #13 / Aug 31, 2011 7:35pm

    Dan Decker

    7338 posts

    stevo_s,

    I apologize for my typos. Dave thanks for sorting me out, that was a late night and I’m not sure where my head was 😉

    I’ll try to replicate your issue with {exp:member:custom_profile_data} and see if we have a bug on our hands.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases