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.

orderby custom field with weight

March 28, 2012 2:02pm

Subscribe [3]
  • #1 / Mar 28, 2012 2:02pm

    atomiccricket

    3 posts

    Hi folks,

    I recently took over development of an EE 2 site from a friend of mine who got out of the freelancing business.  I’m still fairly new at this EE stuff, so pardon me if this question has a really simple answer I’ve overlooked.

    My client runs a shop where she sells something like 250 different pairs of socks. We have them organized by brand and style. We have the catalog displaying items just fine, but she wants it to show the brands in a particular order.

    For instance, she wants all of the Sock It To Me socks to show up first, then another brand, then another brand, etc.  I’ve used the test code…

    {exp:channel:entries channel="products_socks" orderby="sock_supplier" sort="desc" status="Open|Out of Stock" limit="1000"}
        <li>{sock_supplier} - {title}</li>
        {if no_results} Well that's weird, there's nothing here! Try something else. {/if}
       {/exp:channel:entries}

    and that orders the socks by the supplier alphabetically, but I want to specify the supplier order so Sock it to Me comes first, and so forth.  Is there any way to do this?  I’ve tried everything I can think of!

    Thanks,
    -Tobyn

  • #2 / Mar 28, 2012 3:36pm

    Rob Allen

    3114 posts

    Hi zair99 welcome to the forums

    What you’re seeing here is EE’s default way of listing entries using the orderby parameter as you would expect.

    As you really want a custom order there are some things you can try.

    1. Use Stickies
    For all “Sock It To Me socks” product entries mark then as “Sticky” (under the Options tab). This should make those items rise to the top of any list irrsepective of any other sort order.

    2. Use an addon
    The one that springs to min is http://gotolow.com/addons/low-reorder which allows you to apply a custom sort for entries. However as you have 100’s of products that may be a bit cumbersome to work with.

    3. Use two sets of tags in your template and use the search:field_name parameter to filter them

    {exp:channel:entries channel="products_socks" orderby="sock_supplier" sort="desc" 
    status="Open|Out of Stock" limit="1000" search:sock_supplier="Sock It To Me socks"}
    <li>{sock_supplier} - {title}</li>
    {if no_results}No products from Sock It To Me socks {/if}
    {/exp:channel:entries}  
    
    {exp:channel:entries channel="products_socks" orderby="sock_supplier" sort="desc" 
    status="Open|Out of Stock" limit="1000" search:sock_supplier="not Sock It To Me socks"}
    <li>{sock_supplier} - {title}</li>
    {if no_results} Well that's weird, there's nothing here! Try something else. {/if}
    {/exp:channel:entries}
  • #3 / Mar 28, 2012 4:37pm

    atomiccricket

    3 posts

    I’ll check out that addon, but the third option sounds like it’d be about perfect!  I haven’t done much yet with the search:field_name parameter, so it should be interesting. 😊  Thanks for the quick advice and I’ll post again with some results.

  • #4 / Mar 29, 2012 5:09am

    Rob Games

    38 posts

    If your planning on using pagination on these pages I would be inclined to go for option 1 or 2.

  • #5 / Mar 29, 2012 10:47pm

    atomiccricket

    3 posts

    Hmm, yes, pagination is an issue.  Applying the stickiness almost works, but I have two brands that I want to be sticky.  I think I’d like to start a petition for optional ordering weights on custom field items.  😉

    I’m going to keep poking at this and see what I come up with.

  • #6 / Mar 30, 2012 1:18am

    atomiccricket

    3 posts

    Hooray!  I managed to get it to work using JavaScript rather than EE for the pagination.

    {exp:channel:entries channel="products_socks" category="<?echo($cat_list)?>" orderby="sock_supplier|sock_gender|date" sort="desc|desc|desc" status="Open|Out of Stock" limit="1000" search:sock_supplier="Sock It To Me|Gumball Poodle"}
    
     {if <?echo($brand_list)?>}
     
      {if <?echo($gender_list)?>}
     
       [removed]
        entry_ids[total_results] = "{entry_id}";
        total_results++;
       [removed]
        
      {/if}
    
     {/if}
     
    {/exp:channel:entries}

    Followed by the channel entries tag specifying all the rest of the brands, with that same JavaScript, plus a bunch of other crap further in.  Long story short, it works like a charm, but man do I wish it was easier!

    Thanks a bunch guys!

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

ExpressionEngine News!

#eecms, #events, #releases