Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

How to group links by a given field?

Quote Reply
How to group links by a given field?
Can anybody help how to change the script in order to group the links by city name (which is a new field in links table) and show the link listing like this:
<CityName1>
Link1
Link2
<CityName2>
Link3
Link4

thanks!

Last edited by:

AMIXIMA: May 10, 2006, 4:28 PM
Quote Reply
Re: [AMIXIMA] How to group links by a given field? In reply to
Have not tested it myself, but you should try it as:

Quote:
<%if Cityname eq 'CityName1'%>
Link1
Link2
<%elseif Cityname eq 'Cityname2'%>
Link3
Link4
<%endif%>


If you are having a link property with city names in it, and assuming the link property name is Cityname, above might be a solution for you.

Hope this helps.

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] How to group links by a given field? In reply to
Thanks but this not a solution i am looking for, the list should be generated automatically. Also note Link1, Link2 shoud have a city=<Cityname1> and Link 3, Link4 - city=<Cityname2>. So probably this has to be changed in sql statement somewhere like:

for each cityname
select links where city=cityname

if you have a better solution please let me know.

Thanks again!
Quote Reply
Re: [AMIXIMA] How to group links by a given field? In reply to
Use the build_sort_order_category option (Setup => Build Options).

Adrian
Quote Reply
Re: [brewt] How to group links by a given field? In reply to
Adrian,

thanks, if i am not mistaken that feature only sorts the links but it doesn't group them and cannot add city names on top of the link sub-lists like:

Chicago
Chicago Tribune
Chicago Star
...
New York
New York Times
New York Post
...

If i will use build_sort_order_category all i will get is something like this:

Chicago - Chicago Tribune
Chicago - Chicago Star
New York - New York Times
New York - New York Post

probably i need to add a new line in the code like

select distinct city from Links
for each city
Display City

select all from links where city=city
Display list of links

The problem is i am not a programmer nor don't know ever where exactly to look for link loop script...

If you have another idea please let me know.

Thanks again,

Armen
Quote Reply
Re: [AMIXIMA] How to group links by a given field? In reply to
You easily achieve what you want by keeping track of the city when looping through the results. Do something like:
Code:
<%loop links_loop%>
<%if City ne $lastCity%><%City%><%endif%>
<%set lastCity = $City%>
<%include link.html%>
<%endloop%>
in the category.html template.

Adrian

Last edited by:

brewt: May 11, 2006, 4:27 PM
Quote Reply
Re: [brewt] How to group links by a given field? In reply to
Adrian,
I tried but this way i am gatting only city name on the top of each link but i need:

<Cityname1>
<link1 where city=cityname1>
<link4 where city=cityname1>
<link9 where city=cityname1>

<Cityname2>
<link2 where city=cityname2>
<link3 where city=cityname2>
<link5 where city=cityname2>
<link6 where city=cityname2>
<link7 where city=cityname2>

I think your script is not checking "where city=citynameN" for the links.

Please see the following link:
http://www.newspapers24.com/...ers%2Findex.html;d=1

Thanks,

Armen
Quote Reply
Re: [AMIXIMA] How to group links by a given field? In reply to
Oops, put the 'set' in the wrong place and forgot the endif. I updated my previous post with the corrections.

Adrian
Quote Reply
Re: [brewt] How to group links by a given field? In reply to
Adrian, I updated the code but still it is not fixing the main issue where city=cityname1
<Cityname1>
<link1 where city=cityname1>
<link4 where city=cityname1>
<link9 where city=cityname1>

it fails to create subsets of links where city=citynameN. Something has to bechanged in sql statement i assume.

Armen
Quote Reply
Re: [AMIXIMA] How to group links by a given field? In reply to
Oops, forgot to put the $ on the lastCity variable. Updated it again.

Adrian
Quote Reply
Re: [brewt] How to group links by a given field? In reply to
Thanks!!!!!!!!!!!!!!!
it works now!
If you have extra time could please explain what exactly the $ character is doing in this case, I can read the rest of the code, but no idea how adding $ can make the list grouped by cityname?

Again many thanks,

Armen
Quote Reply
Re: [AMIXIMA] How to group links by a given field? In reply to
That template code isn't doing any grouping at all. The grouping is done in the order by from the build_sort_order_category option. All the template code is doing is looking at the City column's value and comparing it to the last link's City value. If it's different, then it prints the City name, otherwise it doesn't print anything. The last problem with the $ was that when making string comparisons with GT::Template with two variables, the variable on the right side needs to be prefixed with a $ (otherwise it turns into a string [in this case 'lastCity']).

Adrian
Quote Reply
Re: [brewt] How to group links by a given field? In reply to
Thanks for detailed explanation! Now I understand how the script functions.
Armen