I need to allow custom sorting of a channel entries loop, so I'm currently achieving this by using segments and URLs like this: mywebsite.com/products/sort/date/asc and mywebsite.com/products/sort/price/asc with the following code:
<ul>
{exp:channel:entries channel="product" orderby="{segment_3}" sort="{segment_4}" pagination="bottom"}
<li>{title}</li>
{/exp:channel:entries}
</ul>
This works fine for ordering by date and other custom fields, but the downside is that the URLs can get a bit ugly as I need to add the custom field short name to the URL, e.g. mywebsite.com/products/sort/cf_product_ugly_custom_field/asc
My workaround has been to name the custom fields I wish to sort by from my usual format of {cf_product_price} to {price}, but this doesn't feel like an elegant solution.
Can anyone think of a more elegant way of doing custom sorting, without having to have the custom field in display in the URL like this? Thanks for any advice.