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.

Listing entires by Member Group ID

October 23, 2012 6:09am

Subscribe [3]
  • #1 / Oct 23, 2012 6:09am

    adsmart

    24 posts

    Hello,

    I’m currently building a site where we have business listings. We have 3 member groups i.e. Bronze, Silver, Gold.

    Depending on the membership group, a member will have more or less options in their SAEF, i.e. additional images etc.

    On my front end listing page of a category, i.e. Bars, I wanted to able to prioritise the listing based on member groups - i.e. Show Gold listings at the top, Silver listings under, then Bronze at the bottom.

    I thought it would be a simple case of running 3 loops in that order something like:

    {exp:channel:entries channel="listing" dynamic="on" category="{segment_3_category_id}" orderby="random"}
    {if member_group =="1"}
    //Gold Members image, title, excerpt
    {/if}
    {/exp:channel:entries}
    
    {exp:channel:entries channel="listing" dynamic="on" category="{segment_3_category_id}" orderby="random"}
    {if member_group =="2"}
    //Silver Members image, title
    {/if}
    {/exp:channel:entries}
    
    {exp:channel:entries channel="listing" dynamic="on" category="{segment_3_category_id}"}
    {if member_group =="3" OR member_group !="1|2"}
    //Bronze Members title, tel/fax/email
    {/if}
    {/exp:channel:entries}

    This doesn’t work - am I right in assuming that the member_group will only hook into logged in members and not allow anything inside an entries loop?

    Is there a work around or better way to do this, I’m aware that 3 loops on the page is not the most efficient approach at the moment - I was thinking of hidden fields in the SAEF i.e. a field called “Priority” where by a value of “GOLD, SILVER, BRONZE” could be conditionally put into a hidden field based on member gorup i.e.

    {if logged_in_group_id =="1"}
    <input name="priority" value="GOLD" />
    {if:elseif logged_in_group_id =="2"}
    <input name="priority" value="SILVER" />
    {if:elseif logged_in_group_id =="3"}
    <input name="priority" value="BRONZE" />
    {/if}

    Obviously this hidden field could be “firebugged” to change the value so it’s not ideal, and I think I would either need to use cusotm query to get the list and organise by priority in one Loop.

    Any suggestions would be greatly appreciated, I’m a little stuck on the best approach here.

  • #2 / Oct 23, 2012 7:24am

    e-man

    1816 posts

    Just use a custom field like your final suggestion, you can order entries by custom field
    http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#orderby
    so you’d only need one loop instead of 3.

  • #3 / Oct 23, 2012 8:01am

    adsmart

    24 posts

    I’ve setup a field (numerical) to test this but the order by is all over the shop. My code below looks fine to me the idea is that the “1” package is gold, “2” silver and “3” bronze, so gold get a span12 (full width) at the top, then the silvers display as half that (span6) then the bronze just output as half again (span3)

    {exp:channel:entries channel="listings" dynamic="on" category="{segment_3_category_id}" order_by="business_package" sort="asc"}
    
    <!--Premium Plus STARTS-->
    {if business_package =="1"}
    <div class="span12 thumbnail">
     {business_images limit="1"}{image_file}{/business_images}
      <h3>{title}</h3>
    <p></div><br />
    {/if}<br />
    <!--Premium Plus ENDS--></p>
    
    <p><!--Premium STARTS--><br />
    {if business_package =="2"}<br />
    <div class="span6 thumbnail"><br />
     {business_images limit="1"}{image_file}{/business_images}<br />
      </p><h3>{title}</h3>
    <p></div><br />
    {/if}<br />
    <!--Premium ENDS--></p>
    
    <p><!--Basic STARTS--><br />
    {if business_package =="3"}<br />
    <div class="span5 thumbnail"><br />
     <address><br />
     <strong>{title}</strong></p>
    
    <p>  {business_building_name}, {business_street_name}, {business_town}</p>
    
    <p>  {if business_telephone}<abbr title="Phone">P:</abbr> {business_telephone}<br />
    {/if}<br />
      {if business_fax}<abbr title="Fax">F:</abbr> {business_fax}{/if}<br />
     </address><br />
    </div><br />
    {/if}<br />
    <!--Basic ENDS--></p>
    
    <p><br />
    {/exp:channel:entries}

  • #4 / Oct 23, 2012 8:07am

    e-man

    1816 posts

    What happens if you use a txt variable (‘bronze’, ‘silver’ etc…) rather than a numerical value?

  • #5 / Oct 23, 2012 8:13am

    adsmart

    24 posts

    Will I not run into an issue with text where by it’s tryin to sort by that customer field and asc or desc will be alphabetically? so:

    BAsic
    BRonze
    GOld

  • #6 / Oct 23, 2012 8:22am

    e-man

    1816 posts

    Could be, but since it’s a hidden custom field you can pretty much name it anything that suits your particular order.

  • #7 / Oct 23, 2012 8:23am

    adsmart

    24 posts

    Tried it and what seems to be happening is the loop is just going through each entry conditional so the patter of output (when I simplfy it to just use h1 for gold, h2 for silver, h3 for bronze - for visual clarity, rather than spans at the moment) 123, 123 etc

    So I get

    Gold
    Sivler
    Brone
    Gold
    Silver
    Bronze

  • #8 / Oct 23, 2012 8:31am

    e-man

    1816 posts

    Hmmm… how about this approach then? You’ll still have 3 loops, but efficient ones as you’re only retrieving a subset.

    {exp:channel:entries channel="your_channel" disable="categories|trackbacks|pagination" search:your_custom_field="gold"}
    // gold output here 
    {/exp:channel:entries}
    
    {exp:channel:entries channel="your_channel" disable="categories|trackbacks|pagination" search:your_custom_field="silver"}
    // silver output here 
    {/exp:channel:entries}
    
    etc…
  • #9 / Oct 23, 2012 11:33am

    adsmart

    24 posts

    Doesn’t seem to work. I’m not familiar with the seach:custom_field inside entries loops, never seen it used before.

    Anyhow, all I get with that for each package is a loop repeating but rather than the 123123 it just loops everything i.e. all bronze,silver,gold in H1, then same in H2 and H3.

  • #10 / Oct 23, 2012 12:07pm

    e-man

    1816 posts

    Can you post your code here?

  • #11 / Oct 23, 2012 12:09pm

    adsmart

    24 posts

    Update: Working now, scrap last reply, I’d pluralized packages - should have been package.

    When you say “subsets” what exactly do you mean.

    I use the approach below and start pulling in say thumbnails for Gold and silver along with say an extra long overview for Gold, is this going to get weighty in terms of queries or would it be considered acceptable.

    <div class="row">
     {exp:channel:entries channel="businesses" dynamic="off" category="{segment_3_category_id}" search:business_package="Gold" orderby="random"}
      <!--Premium Plus STARTS-->
      <div class="span12">
       <div class="thumbnail">
        {business_images limit="1"}{image_file}{/business_images}
        <h2>{title}</h2>
    <p>   </div><br />
      </div><br />
      <!--Premium Plus ENDS--><br />
     {/exp:channel:entries}<br />
     </div><br />
     <br />
     <div class="row"><br />
     {exp:channel:entries channel="businesses" dynamic="off" category="{segment_3_category_id}" search:business_package="Silver" orderby="random"}<br />
     <!--Premium STARTS--><br />
      <div class="span6"><br />
       <div class="thumbnail"><br />
        {business_images limit="1"}{image_file}{/business_images}<br />
        </p><h4>{title} {business_package}</h4>
    <p>   </div><br />
      </div><br />
     <!--Premium ENDS--><br />
     {/exp:channel:entries}<br />
     </div><br />
     <br />
     <div class="row"><br />
     {exp:channel:entries channel="businesses" dynamic="off" category="{segment_3_category_id}" search:business_package="Bronze" orderby="random"}<br />
     <!--Basic STARTS--><br />
      <div class="span3"><br />
      </p><h5>{title} {business_package}</h5>
    <p>  </div><br />
     <!--Basic ENDS--><br />
     {/exp:channel:entries}<br />
     </div>

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

ExpressionEngine News!

#eecms, #events, #releases