Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Changing COOL sort to 'hits' only

Quote Reply
Changing COOL sort to 'hits' only
To change the COOL sort from the way it's done now (by Category, then by Title, hits, etc) you can make a change to the nph-build.cgi in the build_cool_page subroutine:

Code:
# Create the HTML for the individual links.
$total = 0;
while ($link = $sth->fetchrow_hashref) {
$total++;
my $get_link = &site_html_link ($link); ##
$link_output{$link->{'Name'}} .= $get_link ; ##
$link_results .= $get_link ; ###
}

# Create the HTML for the category headers, and join it all together into link_results.
## foreach $category (sort keys %link_output) {
## $category_clean = &build_clean_name ($category);
## $link_results .= qq|<P><A HREF="$LINKS{build_root_url}/$category_clean/$LINKS{build_index}">$category</A>\n|;
## $link_results .= $link_output{$category};
## }

The lines with '##' are the changed ones.
You add 2 lines and change 1 in the top subroutine, and comment out the lines in the bottom one (they are next to each other in the file.

To change the way the links are sorted, edit the parameter in the Links.pm file to whatever you want, and the links will be sorted in that order _without_ being grouped by category.

[made a change to prevent two subroutine calls]

[This message has been edited by pugdog (edited October 18, 1999).]

[This message has been edited by pugdog (edited October 18, 1999).]
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
you could make it just do this:

Code:
$total = 0;
while ($link = $sth->fetchrow_hashref) {
$total++;
$link_results .= &site_html_link ($link);
}

and of course comment out those other lines..

then up a few lines..

ABOVE:

Code:
LIMIT 1000

add

Code:
ORDER BY Links.Hits DESC

or you can just change the whole prepare statement to

SELECT * FROM Links WHERE isPopular = 'Yes' ORDER BY Hits DESC LIMIT 1000

jerry
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
Yeah, you could, but my way leaves the original code there, in case you change your mind Wink

as for doing:

SELECT * FROM Links WHERE isPopular = 'Yes' ORDER BY Hits DESC LIMIT 1000

I hadn't looked far enough ahead to see if it impacts anything else.

The ideal would be to add a parameter to the Links.pm file, OrderByCategory, and if yes, go through the existing procedure with the SortOrder variable, otherwise, use the more direct SELECT method, passing it the SortOrder.


I just didn't want to get too complicated until Links 1.2 is out.... but the grouping by category irks me Smile My most popular links were always at the bottom because their category started with a later letter.




[This message has been edited by pugdog (edited October 19, 1999).]
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
 
Quote:
SELECT * FROM Links WHERE isPopular = 'Yes' ORDER BY Hits DESC LIMIT 1000

You lose the category name then, or will have to look it up multiple times (not nearly as efficent as just letting mysql do it).

Cheers,

Alex
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
Losing the categorys is the whole point <G>

But I think what you are saying, is that the way it's written now, there is an implict JOIN, so that the category name is looked up with the CategoryID. I looked at the code, but I'm not clear how I can access that, so that I get a link-list:

Code:
Category_Clean_linked <BR>
Link
Category_Clean_linked <BR>
Link
Category_Clean_linked <BR>
Link
...

Where _each_ link has the category name preceding it, not grouped.

[This message has been edited by pugdog (edited October 19, 1999).]
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
i thought the point of it was to change it so all the cool links sort by hits....

or was it by category? then by hits..

jerry
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
Yes, to sort by hits... but Alex's way allows you to still put the category with the Link, if you'd want to.
Quote Reply
Re: Changing COOL sort to 'hits' only In reply to
This mod still works with the 1.11 version, the only difference is that Alex has added some code to build_cool_page

Code:
($LINKS{build_pop_cutoff} > 1) and ($total == $LINKS{build_pop_cutoff}) and last;

To check for the number of links being written out. Hopefully, to limit the links to the number specified. Just make sure to leave this right before the closing curly brace at the end of the while loop.

To see it in action, check out the what's cool page at:


http://www.postcards.com/pcSQL/pages/Cool/



The links are sorted by HITS but the category name is pre-pended to it. I also added the extra commentary... (I think I posted that in a thread on HTML bugs...).



------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/