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.

Allow user to choose select ’orderby’ parameter themselves

June 25, 2007 5:50pm

Subscribe [3]
  • #1 / Jun 25, 2007 5:50pm

    open-box

    11 posts

    Hi there,

    i’m just wondering if there is a way i can allow a user to choose what order weblog entries display in?

    I want them to display in -

    orderby=“date” and orderby=“url_title”

    But only i can choose what order the user should see entries in.

    Can i offer say a drop down list, where a user can choose what order they want to view weblog entries in?

    I was thinking of just having 2 identicle templates but just ordering them with the 2 different options for the ‘orderby’ parameter - but this seems abit extreme.

    Does anyone have any better suggestions?

    Thanks in advance.

  • #2 / Jun 25, 2007 5:58pm

    Lisa Wess

    20502 posts

    Yes, you absolutely can do this.  The way I handle this is to pass the orderby in a segment, and then use orderby=”{segment_3}” - create the links so it passes the right parameter type to the orderby, and voila.

    The other options is to use dynamic parameters

  • #3 / Jun 25, 2007 11:53pm

    Derek Allard

    3168 posts

    I just took a moment to move this into the how to forum.  If you have any trouble with either of the methods Lisa raised, just let us know and we’ll help you out lickity split.

  • #4 / Jun 26, 2007 5:19am

    open-box

    11 posts

    I haven’t even tried it, but this looks like exactly what i need.

    Thank you both!

  • #5 / Jun 27, 2007 7:43pm

    open-box

    11 posts

    Hi there,

    i’ve tried the dynamic parameters feature, but i cant seem to get it working.

    Here’s the code if anyone wants to have a look.

    <h3>Sort Items</h3>
    <p><form method="post" value="index.php/shop_online"></p>
    
    <p><select name="orderby"><br />
    <option value="item_regular_price">Sort By:</option><br />
    <option value="item_regular_price">Price</option><br />
    <option value="title">Title</option><br />
    </select></p>
    
    <p><select name="sort"><br />
    <option value="asc">Order In:</option><br />
    <option value="asc">Ascending</option><br />
    <option value="desc">Descending</option><br />
    </select></p>
    
    <p><br />
    <input type="submit" value="Go!" /></p>
    
    <p></form>

    and the weblog code.

    {exp:weblog:entries weblog="add_product" rdf="off" limit="4" paginate="bottom"dynamic_parameters="orderby|sort" }
    
    
            <div class="item">
    
    
    {exp:simple_commerce:purchase entry_id="{entry_id}" success="apnacom/success" cancel="site/index" country_code="GB" currency="GBP" }
    
                {image-small}
                <div class="description">
                    <h2>{title}</h2><p> </p>
    
    <p><br />
    {exp:word_limit total="15"}</p>
    
    <p>{product-description-short}</p>
    
    <p>{/exp:word_limit}         </p>
    
    
    
    <p><br />
                    <a href="http://{permalink=shop_online/details}">more</a><br />
                </div><br />
                <div class="controls"><br />
                    £{item_regular_price} <span>exc VAT</span></p>
    
    <p><br />
    {add_to_cart_button}Add to Cart{/add_to_cart_button}<br />
    {buy_now_button}Buy Now{/buy_now_button}<br />
    {view_cart_button}View Cart{/view_cart_button}</p>
    
    <p> </p>
    
    <p>            </div><br />
            </div></p>
    
    <p><br />
    {paginate}<br />
    Page {current_page} of {total_pages} pages {pagination_links}<br />
    {/paginate}<br />
    {/exp:simple_commerce:purchase}</p>
    
    <p><hr ></p>
    
    <p> </p>
    
    <p> </p>
    
    <p> </p>
    
    <p>{/exp:weblog:entries}<br />
    </div><br />
    </div></p>
    
    <p></div><br />
        </p>
    
    <p></div>

    Any help would be great, thanks.

  • #6 / Jun 27, 2007 7:47pm

    Cocoaholic

    445 posts

    This line:

    <form method="post" value="index.php/shop_online">

    should probably read something like this:

    <form method="post" action="index.php/shop_online/">

    EDIT: hmm typo in the docs?

  • #7 / Jun 27, 2007 8:16pm

    open-box

    11 posts

    Hi, thanks for the reply.

    Ive tried them both but i still cant get it working.

    Possibly something to do with:

    Note:  If you have pagination links on your page they will not retain the page layout options created dynamically using this feature.

    If it is a pagination issue, is there a way round to make this work?

    Thanks in advance

  • #8 / Jun 28, 2007 8:18am

    Derek Allard

    3168 posts

    Cocoaholic is correct, doc typo (thanks sir, we’re on it) and it should read something like

    <form method="post" action="{path="site/shop_online"}">

    And a few more things:
    Can you confirm that you don’t have caching turned on for that template?
    Can you give us a live example?
    What version/build?  You can find this in the footer of your control panel.
    Is your form and weblog entries on the same page?

    Here’s a simple example (I’m going to keep the rest of the template out of it in order to reduce any problems).  Could you try a test template that reflects your site?

    <form method="post" action="{path="template_group/template"}">
    
    <select name="orderby">
    <option value="title">Sort By:</option>
    <option value="title">Title</option>
    <option value="date">Date</option>
    </select>
    
    <input type="submit" value="Go!" />
    
    </form>
    
    <hr >
    
    {exp:weblog:entries dynamic_parameters="orderby" weblog="site"}
    
    {title} : {entry_date format="%F %d<sup>%S</sup>, %Y"}
    
    
    {/exp:weblog:entries}
  • #9 / Jun 28, 2007 8:20am

    Cocoaholic

    445 posts

    @Derek,

    What I meant was, shouldn’t ‘value’ be ‘action’ instead?

    <form method="post" action="{path="site/shop_online"}">
  • #10 / Jun 28, 2007 8:25am

    Derek Allard

    3168 posts

    Sorry, that’s what I had in my example, but I made another c/p error.  Anyhow, I’ve fixed up my post, and the docs will be fixed up shortly (thanks). :red:

  • #11 / Jun 28, 2007 7:13pm

    open-box

    11 posts

    Thanks for the replies.

    Here’s the amended code i’m using.

    <form method="post" action="{path="shop_online/index"}">
    
    <select name="orderby">
    <option value="item_regular_price">Sort By:</option>
    <option value="item_regular_price">Price</option>
    <option value="title">Title</option>
    </select>
    
    
    
    <input type="submit" value="Go!" />
    
    </form>
    {exp:weblog:entries dynamic_parameters="orderby" rdf="off" limit="4" paginate="bottom" weblog="add_product" }
    
    
            <div class="item">
    
    
    {exp:simple_commerce:purchase entry_id="{entry_id}" success="apnacom/success" cancel="apnacom/index" country_code="GB" currency="GBP" }
    
                {image-small}
                <div class="description">
                    <h2>{title}</h2><p> </p>
    
    <p><br />
    {exp:word_limit total="15"}</p>
    
    <p>{product-description-short}</p>
    
    <p>{/exp:word_limit}         </p>
    
    
    
    <p><br />
                    <a href="http://{permalink=shop_online/details}">more >></a><br />
                </div><br />
                <div class="controls"><br />
                    £{item_regular_price} <span>exc VAT</span></p>
    
    <p><br />
    {add_to_cart_button}Add to Cart{/add_to_cart_button}<br />
    {buy_now_button}Buy Now{/buy_now_button}<br />
    {view_cart_button}View Cart{/view_cart_button}</p>
    
    <p> </p>
    
    <p>            </div><br />
            </div></p>
    
    <p><br />
    {paginate}<br />
    Page {current_page} of {total_pages} pages {pagination_links}<br />
    {/paginate}<br />
    {/exp:simple_commerce:purchase}</p>
    
    <p><hr ></p>
    
    <p>{/exp:weblog:entries}

    and i dont have caching turned on, im using version 1.5.2, the form and weblog entries are on the same page - the live example can be found here - http://www.apnacom.com/index.php/shop_online/

    any help is much appreciated.

    thanks.

  • #12 / Jun 29, 2007 5:57pm

    Derek Allard

    3168 posts

    Alright, 1.6 might be worth the upgrade for you.  But at any rate, can you please try this on an ultra reduced test template?  Just the form and a weblog entries tag with title and price?  Post the template here, (whole thing, don’t worry about 2 code tags) and also the url?  I’m just trying to remove other complications for now to narrow things down.

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

ExpressionEngine News!

#eecms, #events, #releases