Gossamer Forum
Home : Products : Links 2.0 : Customization :

Building and sorting Categories on the Homepage

Quote Reply
Building and sorting Categories on the Homepage
Hi,

I (and I think some others too) need a possibility to change the sort of categories
on the homepage. Now they are sorted alphabetically, I would like sorting by ID or
some other sorting-information which is put in other fields (for example the metas) or
in a new added field (where you can put in sorting-numbers for example) to the database.
Does someone have a solution for this problem?

I can't figure it out how it is working.

In site_html.pl there is just placed the variable $category .
I think the sub build_home_page in nph-build.cgi does the creation of the $category.
Is this right? So this sub is responsible for the sorting? How is this working?
Or where is the sorting hided?

Any help is appreciated !!!

Chiao
Johannes
Quote Reply
Re: Building and sorting Categories on the Homepage In reply to
In nph-build.cgi around line 370:

# Now we have to sort the links and categories..
foreach $link ( keys %links ) {
@{$links{$link}} = &build_sorthit (@{$links{$link}});
}
foreach $cat ( keys %subcategories ) {
@{$subcategories{$cat}} = sort @{$subcategories{$cat}};
}

You could try changing it to:

sort { ${$categories}{$b}[2] <=> ${$categories}{$a}[2] } ...

where 2 is the field number you want to sort on. This is untested though, but let me know if it works out (and if it doesn't what happened).

Cheers,

Alex
Quote Reply
Re: Building and sorting Categories on the Homepage In reply to
Hi Alex,

I tried your suggestion, that means I changed
@{$subcategories{$cat}} = sort @{$subcategories{$cat}};
to
@{$subcategories{$cat}} = sort { ${$categories}{$b}[2] <=> ${$categories}{$a}[2] } @{$subcategories{$cat}};

If this was right, there is now effect of it. No change in the order of categories on the homepage.
And even if I try to change the line
@{$subcategories{$cat}} = sort @{$subcategories{$cat}};
to
@{$subcategories{$cat}} = reverse @{$subcategories{$cat}};
there is no effect. So you are sure, that this is the right part?

If I change in site_html.pl around line 405 the line
foreach $subcat (sort @subcat) {
to
foreach $subcat (reverse @subcat) {
there is an effect on the homepage and the order of the categories is now reversed.

Maybe we can build in some new sorting here? (the problem would be, that this has also effect to every categorie-page ...)

Chiao
Johannes
Quote Reply
Re: Building and sorting Categories on the Homepage In reply to
Hello, I've perhaps a solution to sort categories.

I used "Links 2 Non-english Modifications" which allows you to use non english caracters in categories's names.

Thus I place a figure before name of categorie to sort them. This figure dont appear in HTML pages, it has been replaced (thank mod) by the "non english " field added in this Mod.
Quote Reply
Re: [Alex] Building and sorting Categories on the Homepage In reply to
How could I apply this to the What's New page, so I can have the category groups sorted by a different field in the category.def file?

George
Quote Reply
Re: [macbethgr] Building and sorting Categories on the Homepage In reply to
This may help you out:

http://www.gossamer-threads.com/...r%20mod%3F%20;#41304


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Building and sorting Categories on the Homepage In reply to
Thanks, but that does not apply to categories.....
Quote Reply
Re: [macbethgr] Building and sorting Categories on the Homepage In reply to
Sorry, was thinking of this one:

http://www.gossamer-threads.com/...rary%20order;#108860

Note: I print hard copies of the mods I use (and I've used lots), and also save 'em on disk, so they're much easier to find later...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Building and sorting Categories on the Homepage In reply to
Thanks,

I really think that one was close to what I need, but, not quite. I will play with it for a while.... meanwhile if anyone knows how to get it to work, let me know.