Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Sort Specific Links like 1,5,9,12 etc.

Quote Reply
Sort Specific Links like 1,5,9,12 etc.
Hi all,

I always could find a solution of a problem here for years now, but this time a give up Frown
I am looking for this already 2 days so I suppose if someone ever has asked for solution I should find it by now
Let me explain.
I am using static pages, except for HOME and NEW. I have created a new field in LINKS > PROPERTIES called TYPE. I have some values for this field like TOP, BASE, etc. I already have the random command RAND() for reordering the links by every build and I have created Popularity column from 0-9 in the admin links area, but what I would like to be able to do is , by every build ( specifically ) the TOP links to show up every 4th or 5th link. Example: Let say I have 30 TOP marked links in a specific category and the rest are BASE marked links. Build them to show like this starting from the top.

TOP
BASE
BASE
BASE
BASE
TOP
BASE
BASE
BASE
TOP
BASE
BASE
BASE
BASE
BASE
TOP etc.

Until all the TOP links are listed. And bacause I order by RAND() I suppose if this specific order is possible to be done, the TOP marked links will get rotated , but always showing in this special order. I will appreciate EVERY help on this.

VERY BIG THANKS TO ALL THE SCRIPT GURUS HERE HELPING OUT PPL LIKE ME!

Koki
Quote Reply
Re: [Koki] Sort Specific Links like 1,5,9,12 etc. In reply to
No one guys and gals?
Even to tell me if this is possible or not...?
Quote Reply
Re: [Koki] Sort Specific Links like 1,5,9,12 etc. In reply to
I have found this global code from Laura ( if you allow me , Laura ). Is it possible to be modifyed to control the LINKS db so they can be displayed the way I am looking? Interesting is the code on the last 5-6 lines where if it is eq to a No will insert something.....any ideas if that can be used?

sub {
# -------------------------------------------------------------------
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name');
my $sth = $cat_db->select (['Full_Name','ID','Name'] );
my $output=qq~<table><tr valign=top><td width="25%"><table>~;
my $i=0;
while (my ($cat,$ID,$heading) = $sth->fetchrow_array) {
$i++;
my $url1 = $cat_db->as_url($cat);
$output.= qq~<tr><td>~;
my $depth = ($cat =~ tr/\///);
if ($depth > 0){$output .= "&nbsp;&nbsp;"x$depth."<font size=-1>";}
else {$output.="<b>";}
$output.=qq~<a href="$CFG->{build_root_url}/$url1" class="toc">$heading</a>~;
if ($depth > 0){$output .= "</font>";}
else {$output.="</b>";}
$output.=qq~</td></tr>~;
if (($i eq '13')or ($i eq '19') or ($i eq '33') or ($i eq '40')){ $output.=qq~</table></td><td width="25%"><table align=top>~;}
}
$output.="</table></td></tr></table>";
return $output;
}
Quote Reply
Re: [Koki] Sort Specific Links like 1,5,9,12 etc. In reply to
Can be done with loops...? I simply cant figure it out and that makes me crazy..Mad
Quote Reply
Re: [Koki] Sort Specific Links like 1,5,9,12 etc. In reply to
Yes, at first sight I think it can be done with loops.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Sort Specific Links like 1,5,9,12 etc. In reply to
Jeez... Webmaster 33 thanks for the replyBlush

Any idea on how I can achieve this?
How to make the loop work like this:

<%loop links_loop%>
<%if Type eq 'TOP' % 5%> ????
<%elsif Type eq 'BASE' or 'PRIVAT'%>
<%endif%>
<%endloop%>

Conditional 'Type' is not recognized inside category.html. It is a field for DB LINKS....I am very confused with this already
How to make it know that if Type eq 'TOP' need to list it every 5,10,15 etc. links ?

Any help is greatly appreciated and I am sure there will be others that will find this kind of sorting useful as well

Regards
Koki
Quote Reply
Re: [Koki] Sort Specific Links like 1,5,9,12 etc. In reply to
Something what looks to be a solution at first sight, is not guaranteed to really be. Smile
So global is needed anyway... But I still show you what's the problem with looping solution.

I found the following info useful:
<%row_num%> - a counter for what row is being looped, starts at 1.
% (remainder) operator

So my proposed solution would have been something like this:
Code:
<%loop links_loop%>
<%if row_num % 5%>
put your base link here
<%else%>
put your private link here
<%endif%>
<%endloop%>
Well, yes, but we would need to have 2 separate link lists: 1 base, 1 private.
For base, we can use the loop and just ignore the privates.
But we would need a separate private loop to be able to loop through it in order.


2 solutions look solvable:
a) partially reusing the loop above, do a short global, which retrieves the private links from database, and store in another loop, like private_link_loop (IMHO this solution is a little bit slower)
b) solve the problem with a global, which does all the things, and returns just html (db retrieve of base & private link, merging them together, create link template, return output)

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Sort Specific Links like 1,5,9,12 etc. In reply to
I knew you would say GLOBAL . I am nowhere near to Perl Blush ( I am a classical musician) so... , if the codes are not already posted here I would not know how to do it. I tryed with loops only so far as you suggested. I created two different link.html:

link_top.html with code:
<%if type eq 'Top'%><a href="<%URL%>"><%Title%></a><%endif%>
and
link_base.html with code
<%if type eq 'Base'%><a href="<%URL%>"><%Title%></a><%endif%>

but it's screwing everything...Well if I get the idea I can't without that code, maybe I will try to pay someone to write that global for me.
Anyway webmaster33 thanks for your reply

Regards
Koki

Last edited by:

Koki: Mar 25, 2005, 5:37 PM
Quote Reply
Re: [Koki] Sort Specific Links like 1,5,9,12 etc. In reply to
Quote:
I knew you would say GLOBAL .
I was hoping, that it can be solved without global, but I was wrong.

Quote:
I tryed with loops only so far as you suggested. I created two different link.html:
link_top.html with code:
<%if type eq 'Top'%><a href="<%URL%>"><%Title%></a><%endif%>
and
link_base.html with code
<%if type eq 'Base'%><a href="<%URL%>"><%Title%></a><%endif%>
but it's screwing everything...

The problem is, that you want every 5 link to be TOP link. This is such criteria, which I believe can not be solved using just loops, so global help is needed for it.

If you would not matter to have the TOP and BASE links mixed, or have the TOPs first and BASEs after, then the task would be possible to be solved just with loops.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...