Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to let visitors sort articles/list
I used Textpattern to create a webshop, in combination with a Magento shopping cart that opens in a modal window.
My products are now presented as a normal txp article list with options to divide in separate groups using the category tags and a simple search.
It would be cool however to present more manual sorting options to visitors, for example to let them sort on price, publication date, title, etc.
These are all values listed in custom fields
Does anyone have any suggestions?
Cheers!
Last edited by Karsten (2013-11-08 12:06:58)
Offline
Re: How to let visitors sort articles/list
HI Karsten,
you can use <txp:article_custom sort="custom_n" />
, where custom_n are your specific custom field. E.g custom_1 for price.
You can f.i. choose the sort value by a given GET parameter.
Short pseudo code:
<form action="/" method="get">
<select name="mysort">
<option value="custom_1">Price</option>
<option value="custom_2">Date</option>
<option value="custom_3">Title</option>
<option value="custom_4">Size</option>
</select>
<input type="submit" value="do sort" />
</form>
<txp:if_get_parameter name="mysort">
<txp:article_custom sort='<txp:get_paramenter name="mysort" />' section="xxx" limit="xx" etc. pp />
<txp:else />
<txp:article_custom section="xxx" limit="xx" etc. pp />
</txp:if_get_paramter>
Do some sanitization in <txp:get_paramenter name="mysort" />
and all should be fine.
Last edited by trenc (2013-11-08 12:24:37)
Digital nomad, sailing the world on a sailboat: 32fthome.com
Offline
Re: How to let visitors sort articles/list
If no pagination is involved, you can also do it in Javascript, for example with jQuery tablesorter plugin.
Offline
Re: How to let visitors sort articles/list
the article_custom tags does not allow pagination if I’m right? and this is needed of course.
Offline
Re: How to let visitors sort articles/list
There are some pagination plugins out there. Maybe one will need your fits or try a handmade pagination
Digital nomad, sailing the world on a sailboat: 32fthome.com
Offline
Re: How to let visitors sort articles/list
Karsten wrote:
the article_custom tags does not allow pagination if I’m right? and this is needed of course.
You are right, grab etc_pagination:
<form action="/" method="get">
<select name="mysort">
<option value="custom_1">Price</option>
<option value="custom_2">Date</option>
<option value="custom_3">Title</option>
<option value="custom_4">Size</option>
</select>
<input type="submit" value="do sort" />
</form>
<txp:article_custom sort='<txp:php>echo txpspecialchars(gps("mysort"));</txp:php>' limit="10" section="xxx" etc.
offset='<txp:etc_offset pgcounter="page" pageby="10" />' />
<!-- navigation bar -->
<txp:etc_pagination pages='<txp:etc_numpages pageby="10" section="xxx" etc. />' pgcounter="page" />
Offline
Re: How to let visitors sort articles/list
The article tag allows you to sort by custom field too. Unless I’m missing something you can use Trenc’s original code and plug it into a <txp:article />
tag.
EDIT: for numeric values you might need to cheat a little. For example, the price field might need to be written sort="custom_1 + 0"
(or something like that) to make sure it treats it as a numeric field type, otherwise 5 is “greater than” 10!
Last edited by Bloke (2013-11-08 13:21:01)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: How to let visitors sort articles/list
Thanks for the feedback thusfar, particularly the combo of Bloke and Trenc seem interesting as that should result in a paginated list. I’ll look into it and see if I can get it to work!
Cheers!
Offline
#9 2013-12-12 12:15:08
- dorka
- Member
- Registered: 2012-10-04
- Posts: 90
Re: How to let visitors sort articles/list
Hi, it seems I’ve found exactly what I’m looking for here, but I’m a little confused. Could someone explain pls what
<form action="/" method="get">
in Trenc’s example stands for in real txp code?
Thanx
Last edited by dorka (2013-12-12 12:16:34)
Offline