Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-10-31 11:20:34

ferenczi
Member
Registered: 2005-01-31
Posts: 67

best way to give user option to sort/display articles differently

I’ve searched through the forum and also the FAQ; I think that what I’m trying to do can be accomplished with conditionals, but I haven’t found examples or discussions about it and I can’t figure out how to do it. Apologies in advance if this has already been addressed.

I’m trying to put together a simple site for a performer. On a page called “performances,” I have a list of ten performances covering dates ranging from the recent past to the near future (using chh_article_custom).

But I would like users to have the option to sort/display a complete chronological list if they so choose. The easiest way would be to have a link leading to another page where the performances would all be listed in ascending order. But I think it would be more elegant to be able to toggle between these two “views” (current showing a range and comprehensive listed in straight ascending order) on the same page. On page load the default “view” would be the limited list of current performances.

Can someone tell me if this is possible using conditional statements and, if so, direct me to a resource with more information? I’ve also looked through textbook and Textpattern Solutions but don’t see what I’m looking for.

Last edited by ferenczi (2007-10-31 11:25:47)

Offline

#2 2007-10-31 12:50:55

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: best way to give user option to sort/display articles differently

There are a number of approaches:

  1. easiest: create “list by …” links that add a ?&sortby=… to the link and use use chs_ifurlvar to detect which setting is active. See this thread for more details of a similar setup. Disadvantages a) it needs a page reload, it’s not remembered. To remember use chs_cookie and save the current user sortby setting in a cookie. Advantage you can link directly to a particular sort order.
  2. create all the different lists on one page each in different divs, use css to hide the lists you don’t want to see and create links/buttons to switch between views. Advantage: does not require page re-load so instantaneous, Disadvantage: longer page load times due to more content plus repeat database queries.
  3. If the data format in each list is near identical but simply sorted differently, put it into a table (yes you heard right – you can always style it to look like a list) and then use a tablesorter javascript such as this jquery tablesorter re-sort the table via js. Advantages: more or less instantaneous but requires javascript.

TXP Builders – finely-crafted code, design and txp

Offline

#3 2007-10-31 14:49:38

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: best way to give user option to sort/display articles differently

Your could also use some plain php and in-build function, like:

<txp:php>
	echo article_custom(
	array(
		'section' => $GLOBALS['pretext']['s'],
		'sort' => (gps('sort') && gps('order')) ? gps('sort').' '.gps('order') : 'Title asc',
		'limit' => 9999,
		'form' => 'performances-list',
	));
</txp:php>

And now you can change the sorting by simple link – in example:

http://www.your-domain.com/performances/?sort=posted&order=asc sorts articles by posting time,
http://www.your-domain.com/performances/?sort=title&order=asc sorts articles by title
http://www.your-domain.com/performances/?sort=custom_1&order=desc sorts articles by custom field nurmer one

And it’s so easy.

Cheers!

Last edited by Gocom (2007-10-31 14:50:01)

Offline

#4 2007-10-31 16:50:31

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: best way to give user option to sort/display articles differently

Gocom, I’ve not tried it but that looks very elegant!


TXP Builders – finely-crafted code, design and txp

Offline

#5 2007-10-31 23:00:50

ferenczi
Member
Registered: 2005-01-31
Posts: 67

Re: best way to give user option to sort/display articles differently

Wow, Gocom, thank you so much once again. I’m going to look over your recommendation more carefully and try to implement it. It’s difficult for me to follow, but I hope that I’ll be able to make it work since it sounds like it’s exactly what I’m after.

Sorting articles according to range, which chh_article_custom allows me to do, is crucial so my hope is that I can make that work with this schema.

Thanks again.

Offline

#6 2007-10-31 23:06:58

ferenczi
Member
Registered: 2005-01-31
Posts: 67

Re: best way to give user option to sort/display articles differently

Gocom wrote:

?sort=custom_1&order=desc@ sorts articles by custom field number

Okay so it sounds like I should use a custom field to sort articles falling within a certain range, e.g.,

time="-45 days,+3 months" sortby="Posted" sortdir="asc"

Offline

Board footer

Powered by FluxBB