Gossamer Forum
Home : Products : Gossamer Links : Discussions :

A B C D E sub-category listing

Quote Reply
A B C D E sub-category listing
I currently am using the yahoo template for my web site. Before when I was using the orginal default the listings within the categories looked like this:
a b c d e f g h ( etc etc.)

But now it looks like:
A E
B F
C G
D H

i either want it as a straight line so that it doesnt take up the entire screen for the alphbet in columns or to have it not split it up at all and have long pages.

Please tell me where I can do this and how???/

thank you thank you

Quote Reply
Re: A B C D E sub-category listing In reply to
are you sure they went across the screen using the default templates?

i have requested this a number of times (search for alphabar) but did not get much of a response.

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: A B C D E sub-category listing In reply to
I don't think you can do it using just the templates, since the 'subcategory.html' template only contains the formatting for any entry inside a table cell.

You'd need to add a field to the category table, something like 'Alphabar' (Yes/No) to identify the category as one that belongs across the top of the page, then edit "sub site_html_print_cat" in SiteHTML.pm to selectively place the categories in a new table that gets printed above the 'normal' subcategories.

I may have a look at the mod again and see if I can't port it to 2.x, but it may be while as I'm busy working on a moving all my sites to a dedicated server. Smile (can't wait!!)

All the best
Shaun

Quote Reply
Re: A B C D E sub-category listing In reply to
yeah that is what i thought you had to do. I tried to port the mod from links SQL 1 but failed dismally.!

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: A B C D E sub-category listing In reply to
Okay, I've managed to get the basic idea of 'Alphabar' mod across, but I'm not sure how usable it is in its current state. (I haven't spent too much time on it)

It's a table added to the top of the 'normal' sub-category table, so it cannot be placed separately at the moment. It would be better if the alphabar table used a seperate tag, then it could be placed anywhere!

It also doesn't 'remove' the Alphabar cats from the normal column count, so the 'normal' categories end up all over the place, but you can get the basic idea. I had problems with strict when trying to port the counter from my 1.13 mod, so someone else may have to help with this part!

What is should do, is to count the number of 'Alphabar' subcategories and remove x many from the 'normal' column count so that the calculation used to split the columns in two has the correct total normal sub-cats and the normal sub-cats display evenly.

Anyway, here's what I've got so far:

Add a new field to the Category table:

Column Name: Alphabar
Column Type: ENUM(No, Yes)
Not Null: Yes
Default: No
Form Display: TEXT

Make a copy of your subcategory.html template, and name it 'alphabar.html' (remove any <li> type formatting in since alpha-cats are not in a DIR type list!)

Now we edit sub site_html_print_cat { in SiteHTML.pm:

Note: $output has been changed to $cattable


Code:
sub site_html_print_cat {
# --------------------------------------------------------
# This routine prints out a list of categories.
#
my $subcat = shift;

my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames, $cattable, $alphatable, $category_alpha);
my $parent_cat = shift @$subcat;

my $breakpoint = int (($#{$subcat}+1) / $CFG->{build_category_colum
ns}) + ( (($#{$subcat}+1) % $CFG->{build_category_columns}) ? 1 : 0);


# Print Header.

$alphatable = qq|<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width="100%" valign="top">\n|;

my $table_head = $CFG->{build_category_table} || '';
my $width = int (100 / $CFG->{build_category_columns});
if ($CFG->{build_category_columns}) {
$cattable = qq|<table $table_head><tr><td width="$width%" valign="top"><dir>\n|;
}
$i = 0;
my $cat_db = $DB->table('Category');

foreach $cat_r (@$subcat) {
# Get the URL and the Category name.
$category_url = $CFG->{build_root_url} . "/" . $cat_db->as_url ($cat_r->{Full_Name}) . "/" . $CFG->{build_index};
($cat_r->{Name} =~ m,.*/([^/]+)$,) ? ($category_name = $1) : ($category_name = $cat_r->{Name});
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

# Append @ if we are using Yahoo style cats, and it is related.
if ($cat_r->{Related}) {
if ($cat_r->{RelationName}) {
$cat_r->{Short_Name} = $cat_r->{RelationName};
}
else {
if (exists $parent_cat->{Name} and ($cat_r->{Short_Name} eq $parent_cat->{Name})) {
my ($short) = $cat_r->{Full_Name} =~ m,([^/]+)/[^/]*$,;
$short and ($cat_r->{Short_Name} = $short);
}
else {
$cat_r->{Short_Name} = $cat_r->{Short_Name};
}
}
}

# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($CFG->{build_category_columns}) {
($i > 0) and !($i % $breakpoint) and ($cattable .= qq|</dir></td>\n<td valign="top" width="$width%"><dir>\n|);
$i++;
}
if ($cat_r->{Alphabar} eq 'Yes') {
$alphatable .= Links::load_template ('alphabar.html', $cat_r, 0);
}
else {
$cattable .= Links::load_template ('subcategory.html', $cat_r, 0);
}

}
# Don't forget to end the unordered list..
if ($CFG->{build_category_columns}) {
$cattable .= "</dir></td></tr></table>\n";
}
chop $alphatable;
$alphatable .= "</td></tr></table>
\n";

$output = $alphatable;
$output .= $cattable;


return $output;
}
---------------------------------------

Since the forums can sometimes alter the appearance of the code, I've also placed this section as a .txt file on my server for download and copying:

http://www.qango.com/.../alphabar_beta_1.txt


If you do manage to solve some of the remaining issues with this mod, or indeed get it ported to a plugin, I'd love to see the results Smile

All the best
Shaun

Quote Reply
Re: A B C D E sub-category listing In reply to
Okay, here's the main thing that needs fixing with the mod;

The variable $breakpoint is a count of all the subcategories, and is used for defining when to create another table column.

I had this routine in my 1.13 mod that counted 'out' the Alphabar sub-cats, and removed the number from $breakpoint, so it was set to the correct total number of 'normal' sub-cats and displayed them properly:

Code:
my @names = keys %{$subcat};

$nonalpha = 0;
foreach $catcount (@names) {
$cat_z = $subcat->{$catcount};
$alphacatcount = $cat_z->{Alphabar};
if ($alphacatcount ne "Yes") {
$nonalpha++;
}
}
When trying to use this same routine I now get the error:

Bad index while coercing array into hash at ..... line 116 (I've also has strict errors as well, but I'm not quite as good at PERL as I wish)

If I print $catcount it shows the field names for the relevent category fields, but no field values. I want to test the value of the field 'Alphabar' to see if it is equal to "Yes", and if so, add '1' to the counter.

Any ideas on how I can get this routine working would be much appreciated Smile

Thanks - Shaun

Quote Reply
Re: A B C D E sub-category listing In reply to
Do you guys have examples of what you want the page to look like, or do?

I started the alphabet bar mod, and turned it into a "search" by first letter mod, but the logic started out to be an alphabet bar.

I might be able to add this in, and keep it as a plug-in so you don't modify all the code. Links is still changing, and code modifications to the body code is not a good idea. The plug-ins are still the way to go!

The mod was targeted for "links" not categories, so I really need to "see" what you want to do, and what you are trying to make it look/work like.



PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: A B C D E sub-category listing In reply to
http://dmoz.org/Arts/Movies/Titles/

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: A B C D E sub-category listing In reply to
Pugdog,

Sounds great - a plugin would obviously be better Smile

I'm still not sure how plug-ins work though, and from what I've seen and read they look really complicated, especially with all the 'hooks' for various GT::this, SQL::that, and Links::etc. ?

I'd love to have a step-by-step tutorial that runs through the basics of creating plug-ins, just like some of the PERL tutorials I've read that have helped me understand it a little better.

Can you quite literally do anything with plug-in's, or will there still be the odd occasion when a change has to be 'hard-wired' (hacked) into the code? or are plug-ins suitable for particular jobs/mods?

All the best
Shaun

Quote Reply
Re: A B C D E sub-category listing In reply to
If you've been following my progress on the other plug-ins, there is a lot you can't do with a plug-in. But, where the plug-in will be useful, is during an install, where it can load the templates and put the scripts into the right locations. It can set up default parameters, and give the users a way to edit them. Also, it gives a way to set up things to hook into the display routine if added values have to be passed to each of the templates.

The big advantage of the plugins is packaging and installation. It also keeps your code clean.

PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: A B C D E sub-category listing In reply to
Ok.

Looking at Dmoz, the lettered subcategories are _true_ subcategories, and then each of those has the movie title as a subcategory, and then links.

The easiest way for doing something like this might be to re-think what is going on.

Obviously, you can't assume these are leaf nodes, because they are not, they are at least one level up from the leaf.

So, what about adding a field to the category record, called "Alpha_Bar".

When a category page is listed, if the "Alpha_Bar" field is set, then rather than using the standard <%categories%> tag, you would use an <%if%> tag, that uses an alternative layout.

From what I'm seeing, what you want is the alpha bar, rather than the categories in 2 or 3 columns.

<%if Alpha_Bar%>
<%alpha_bar_tag%>
<%else%>
<%category%>
<%endif%>

Since the next version of links should have moved completely to <%loop%> tags, the processing of <%category%> should take place inside the tmplate, so the tags would look like:

<%if Alpha_Bar%>
<%loop category%>
<%include alpha_sub_cat.html%>
<%endloop%>
<%else%>
<%loop category%>
<%include subcategory.html%>
<%endloop%>
<%endif%>

Of course it would be a bit more complicated, since you'd have to take into account the two different formatting needs of the two templates, but this is the gist of it.

Does this make sense, and do what you are trying to accomplish?

My alpha bar mod was more for displaying the links ie: leaf nodes.

PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: A B C D E sub-category listing In reply to
yes pugdog this is exactly what i/we want. you go into a category say Movies

then the script runs through all the sub-categories, if sub-category is alphabar, add it to the alphabar display if not dispaly normally.

As i said elsewhere i think, the alphbar is just another way to display categories in a condensed way.

In the Movies case it just happens that there are sub-cats there as well however I can think of other times when i would use it and it would not be sub cats just links so.

www.ascifi.com/links/stargate/fan_pages/A
www.ascifi.com/links/stargate/fan_pages/B

(they don't exist before trying)

etc would be for just links.

Having this is/elseif alphabar type thing could handle both.

ASciFi.com http://www.ASciFi.com/
Help Desk http://www.Techuk.com/HelpDesk/
Quote Reply
Re: A B C D E sub-category listing In reply to
I'll hang-fire on this then and see what happens, sounds like there are more changes afoot, and the looped processing thingy for the templates sounds like it could supplement a lot of the hard-coded mods people have made previously and give some very funky new ones!! Smile

All the best
Shaun