Gossamer Forum
Home : Products : Links 2.0 : Customization :

Categories in arbitrary order on HP (a mod)

Quote Reply
Categories in arbitrary order on HP (a mod)
Sorry if this has been posted before in the past, I could not find it, so I made the changes and thought someone else might be able to use it. It's the first mod of any length at all I've posted, so let me know if I should be posting them in a different way, or if the instructions are not clear. --Lloyd

Display your categories in an arbitrary order on your home page in Links 2.0
-----------------------------------------------------------------------------

By: Lloyd Sommerer: lloyd@gatheringspot.com

Example: http://churchsite.gatheringspot.com/links2/
Code:
NOTE: If you have made other modifications, please take the
time to make sure you are not breaking them as you
make these changes. In most cases here you can see
just what was changed and make any needed adjustments.
The Modifications...
---------------------------
Code:

**************************************
* In links.cfg *
**************************************
FIND THE FOLLOWING LINE
Code:
# Date Routines

ADD THESE 3 LINES ***BEFORE*** IT
Code:
# Category Sort Field, the position in your category database of the field to sort
# the categories by when displaying them on your home page.
# [0=ID] [1=Name] [X=Your New Field] (you have to replace "X" with a number)
$cat_sort_field = 0;
Code:

**************************************
* In site_html_templates.pl *
**************************************
FIND THE FOLLOWING LINE
Code:
foreach $subcat (sort @subcat) {
AND REPLACE IT WITH THESE 2 LINES
Code:
sub byfield { $category{$a}[$cat_sort_field] cmp $category{$b}[$cat_sort_field] };
foreach $subcat (sort byfield @subcat) {
Code:

**************************************
* in category.def *
**************************************
NOTE: You can ignore this section if you are going to use one of the fields already
present in the category database for your sort order (I use the ID).

FIND THIS SECTION (IT'S AT THE TOP)
Code:

# Database Definition: CATEGORIES
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Name => [1, 'alpha', 40, 75, 1, '', '^[\w\d/_-]+$'],
Description => [2, 'alpha', '40x3', 500, 0, '', ''],
Related => [3, 'alpha', 0, 255, 0, '', ''],
'Meta Description' => [4, 'alpha', 40, 75, 0, '', ''],
'Meta Keywords' => [5, 'alpha', 40, 75, 0, '', ''],
Header => [6, 'alpha', 40, 75, 0, '', ''],
Footer => [7, 'alpha', 40, 75, 0, '', '']
);
PLACE THIS LINE UNDER THE LAST ENTRY IN THE LIST JUST BEFORE THE ");"
Code:
'Category Sort' => [8, 'numer' ,5, 8, 0, '', '']
NOTE: The field id, in this case 8 should be changed to reflect the fields position
in your database. Don't forget to place a comma at the end of the entry on the line
above Category Sort.

NOTE: If you added the field above, then you also need to edit your categories.db file.
The easiest (depending on the size of your database) way to do this is to open
categories.db in a text editor and add a "|" to the end of each line. If you'd like,
you could also set your display order at this time by entering "|1", "|2", "|3" and
so forth (lower numbered categories are displayed first).


END OF MOD

FAQ
----


Q: Did you copy the format of this mod from John Gotze?
A: Yeah, pretty much. Don't tell him.

Q: My categories are sorted by string ("12" > "20") even though I'm trying to sort by a numerical field. What should I do?
A: Change "cmp" to "<=>" in the modification you made to site_html_templates.pl above.

Q: How can I sort in the opposite order (Z..A or 100..0)?
A: Switch "$a" and "$b" in the modification you made to site_html_templates.pl above.

Q: What do I do if I have another question?
A: Post it as a reply to this message and I'm sure someone will answer it forthwith.

Q:How do you modify the order of the subcategories on your home page if you are using the yahoo sub cat mod?
A:In site_html_templates.pl replace this line:
foreach (sort @{$subcategories{$subcat}}) {
with this line:
foreach (sort byfield @{$subcategories{$subcat}}) {
Quote Reply
Re: Categories in arbitrary order on HP (a mod) In reply to
Thanks for posting the codes...although I believe that similar codes for random categories was posted awhile back in this forum.

Regards,

Eliot Lee

Quote Reply
Re: Categories in arbitrary order on HP (a mod) In reply to
How do you modify the order of the subcategories on your home page if you are using the yahoo sub cat mod?

ex
Sports
baseball, football, soccer

to

Sports
football, soccer, baseball

Thanks

Travis

Quote Reply
Sorting sub categories. In reply to
I'm a little suprised that it didn't work just the way you described it. That's what I use it for on my home pages. Give me a little more information, and maybe we can figure out what's going on.

Are your main categories sorting the way you want them to?

What field are you sorting by in your category.db file?

Lloyd Sommerer
www.sewardweb.com

Quote Reply
Re: Sorting sub categories. In reply to
Isn't the subcat sorting a function of the yahoo mod?

Are you using Widgetz yahoo mod?

If so, just specify how you want the subs to be ordered. In the Description box of the category, do something like this:

(football, soccer, baseball)1

to get

Sports
football, soccer, baseball, ...

OR

(soccer, football, baseball)2

to get

Sports
soccer
football
baseball

HTH

DT


Quote Reply
Re: Sorting sub categories. In reply to
Oops, I added Yahoo style sub categories to my page AFTER I did this mod, and forgot that I did have to go back and make a change to get the sub categories to sort correctly.

I added that change to the FAQ section of the original post. And please note that I have not tested this new change to any degree, and I don't know how it will interact with the built in sorting (which I have never used) of the Yahoo Mod. But I suspect you will not have any trouble, and it certianly won't hurt any data. It might sort in...um...interesting ways if you try to use both.

Lloyd Sommerer

Quote Reply
Re: Categories in arbitrary order on HP (a mod) In reply to
I tried this mod, but then got the following error when I went to build the pages:

Error including libraries: syntax error at /webs/www.torontoced.com/server/cgi-bin/admin/site_html_templates.pl line 390, near "= ;"

Make sure they exist, permissions are set properly, and paths are set correctly.

Any idea what might be causing that? I do have a mod from cgi-resource.co.uk installed that lists the subcats on the home page - could that somehow be clashing with it?

Quote Reply
Re: Categories in arbitrary order on HP (a mod) In reply to
The error message seems to indicate that the error is near line 390. But I don't know if you've done any other modifications to that file. If you have not done any other modifications, then the error does not seem to be with the 2 line change that you should have made to site_html_template.pl

If you'd like to email the file to me, I'll take a look at it, but I'll need to know if you've done any other mods.

Lloyd Sommerer
lsommerer@sewardweb.com

Quote Reply
Re: [lsommerer] Categories in arbitrary order on HP (a mod) In reply to
Is there a way to use this sorting on JUST the homepage and leave it alphabetically on the rest of the pages? It works perfectly the way I need it on the homepage, but the subcategories are out of order on the rest of the pages. I am sorting on the ID field (Field 0 in the database.).

Thanks in advance.

Charlie
Quote Reply
Re: [cvance] Categories in arbitrary order on HP (a mod) In reply to
I'm having the very same problem: after the mod, the subcategories appear to be scrambled like this:

9 - 10 - 11 - 12 - 1 - 2 - 3 -4 - 5 - 6 - 7 - 8

You may have a look at my work in progress here:
http://www.stonepages.com/megalinks/
and see how the subcategories look scrambled here:
http://www.stonepages.com/...d_Prehistoric_sites/

Any help would be greatly appreciated!!
Quote Reply
Re: [Nightjar] Categories in arbitrary order on HP (a mod) In reply to
OK, I finally found a way to make those cats appear in any desired order. Just apply the "non english text" mode by Matthias Berndt. You can find the mod here: http://www.gossamer-threads.com/...urces/jump.cgi?ID=28

Then you can choose the order of the categories just renaming them (01, 02, 03), while on the "non english name" space you can put the name that will be shown on the main page.

Hope this helps!

Last edited by:

Nightjar: Mar 8, 2003, 12:47 AM
Quote Reply
Re: [Nightjar] Categories in arbitrary order on HP (a mod) In reply to
I use the nonenglish mod, yahoo-style, and sort them using the modified version of priority logo mod. Works fine, the cats and subcats ae in the order I assign them. The mod adds a field, and you rank each cat by a number, and they are then arranged in that order.


Leonard
aka PerlFlunkie