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

Yahoo Sub Categories

Quote Reply
Yahoo Sub Categories
Hello everyone,

In Links 2.o Widgetz had made a mod that allows you to display the sub categories for each main category on the home.html template.

Is this mod available foe LinksSQL?

------------------
James L. Murray
VirtueTech, Inc.
www.virtuetech.com


Quote Reply
Re: Yahoo Sub Categories In reply to
That's been asked a lot.... I think several hacks were posted, but no real "solution" other than hard-coding them in.

It's _probably_ on Alex's to-do list, down around item 2,392,392 for Links SQL <G>... but it probably _is_ there ... if for no other reason than to satisfy all the requests Smile

Because the category hierarchy is generated each time, and then stored, it should be possible to read that, and generate a "home" page that looks different.

There have been a lot of suggestions and requests for a variety of mods that essentially expand upon the functionality of the "home" page generation.

The advantage of the Links set up, is that the home page build routines are separate from the category pages, so you can modify them to do what you want without affecting the rest of the program.

I've even asked Alex if there was a way to abstract this out one more level, so that each sub-category was in effect it's own mini-links site, so that each category could have a different look/feel and even use a different links database (or subset of links fields). This would give much more flexibility to the site... allowing each each "level" to have a "home" page, and the top of the site to have a "portal" page that could even be generated by a different program that just read statistics out of the links databases (this would allow portal building, and using SSI on the home page, but not on the rest of the site).

All cool things that are possible, and don't require too much effort to do -- except that all the effort is Alex's <G>

The reason is that if too many parallel development efforts occur, then they will likely be incompatible.

Maybe with the 1.2 release, Alex will be able to solidify the interface, and publish developer guidelines, so that 3rd parties can take charge of parts of the build/display process and make "plug-ins" that replace the "standard" functionality of the Links modules through all releases ... not just a specific version.

This "subcategory" mod would be an example of such a "plug in"



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








Quote Reply
Re: Yahoo Sub Categories In reply to
i already posted this mod in the forum......

------------------
Jerry Su
Links SQL User
------------------
Quote Reply
Re: Yahoo Sub Categories In reply to
I think this is it. Is it?

http://www.gossamer-threads.com/scripts/forum/resources/Forum9/HTML/000163.html
Quote Reply
Re: Yahoo Sub Categories In reply to
That is the thread:
www.gossamer-threads.com/scripts/forum/resources/Forum9/HTML/000163.html

However, that thread tells you how to do it before Alex incorporated the Subcategory.html template.

Widgetz's code describes the following in HTML_Templates.pm to change:
Code:
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if ($description !~ /^\s*$/sm);
$output .= qq|</dl>|;

It now looks like this:
Code:
# 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).
($i and ($i % $breakpoint)) or ($output .= qq|</td><td class="catlist" valign="top">\n|);
$i++;
defined $dynamic and &load_user ($dynamic, $cat_r);
$output .= &load_template ('subcategory.html', { %$cat_r, %GLOBALS }, undef, $template);
}
# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

How do I incorporate this into the new code?

------------------
James L. Murray
VirtueTech, Inc.
www.virtuetech.com


[This message has been edited by Ground Zero (edited February 07, 2000).]
Quote Reply
Re: Yahoo Sub Categories In reply to
That's what I had thought... the previous solution had not been updated to work with the 1.1l changes.

I'm still catching up. Being down for a week+ makes catching up hard!
Quote Reply
Re: Yahoo Sub Categories In reply to
Well, I got something to work in the new version of links. Don't know if it's the best way, but I only had to do it once and it works in both building and paging. If anyone notices any bugs, please let me know. It may not be as flexible as widgetz, but I think if you tap into the foreach statement you can do alot more with it. I actually need to list out all my subcategories, so I'm not using the foreach to it's potential.

Anyway you can see it working at:
http://www.nmculturenet.org/cgi-bin/webman/page.cgi?g=&t=nmcn&d=1&db=Artisans

So here's what I did:

In HTML_templates.pm

sub site_html_print_cat {

Add to the my list at the top
$sub_category_name, $sub_category_url

Then after

else { $cat_r->{'Days_Old'} = ''; }

Add:


# Get any subcategories
# Check the Links.pm file to see if we've turned on build_sub_categories. I like Alex's advice about making stuff like this optional. So if you want this you have to add this variable to Links.pm and set it to 0 or 1. If you don't remove the first if {}
if ($LINKS{build_sub_categories}) {
my $link_db = new Links: BSQL $LINKS{admin_root_path} . "/defs/Category.def";
my $subnames = $link_db->get_sub_categories ($cat_r->{'ID'});
my $i = 0;
foreach my $subcat (@$subnames) {
$i ++;
my $sub_category = &build_clean_name ($subcat->{Name});
my $sub_category_url = $LINKS{build_root_url} . "/" . $sub_category . "/";
my $count = $sub_category;
my $last = rindex ($sub_category,"\/");
++$last;
my $short =substr($sub_category, $last, 40);
$short =~ s/_/ /g;
$cat_r->{'sub1'} .= qq~<br><a href="$sub_category_url">$short</a>~;

#The <br> in the line above is the separator
#between the subcategories, so if you want
#them separated by a comma, you'll need to
#use a comma at the end (I'm not sure how to
#get rid of the trailing comma if you do that
#though.
}
}


Now, just add <%if sub1%><%sub1%><%endif%> to subcategory.html.


It works for me anyway.

Also, because I wanted 1 column subcategory listings on the homepage and two column subcategory listings on the Category pages
I copied this subroutine and named it to sub site_html_print_cat_home {

Then changed:

my $breakpoint = int (($#names+1) / $LINKS{build_category_columns}) + ( (($#names+1) % $LINKS{build_category_columns}) ? 1 : 0);

to:

my $breakpoint = int (($#names+1) / $LINKS{build_category_home_columns}) + ( (($#names+1) % $LINKS{build_category_home_columns}) ? 1 : 0);

also changed:

$output .= &load_template ('subcategory.html', {

to:
$output .= &load_template ('subcategoryhome.html', {


In Links.pm I added this variable to determine the number of columns I wanted on the homepage.

$LINKS{build_category_home_columns} = 1;


You'll have to create subcategoryhome.html in your template directory.

Be sure to add site_html_print_cat_home to the list of subroutines at the top of HTML_templates.pm (It won't work otherwise)

#Then in nph-build.cgi sub build_home_page {

Change:
$category = &site_html_print_cat ($root_cat_r) if ($root_cat_r);

to:
$category = &site_html_print_cat_home ($root_cat_r) if ($root_cat_r);

I think that's all.

Again, if there's anything wrong with doing it this way, I hope someone will let me know and offer some better suggestions.

Peace all.

Kyle
Quote Reply
Re: Yahoo Sub Categories In reply to
Just out of curiosity, what did that smile face replace in your source code there? I realize that you type [colon]D to get it, but when I try to substitute that, I get software errors when I try to build the site.
Quote Reply
Re: Yahoo Sub Categories In reply to
Your best bet is to click the "Edit" button in the users post above to get the hard code from his or her post.

------------------
James L. Murray
VirtueTech, Inc.
www.virtuetech.com


Quote Reply
Re: Yahoo Sub Categories In reply to
the smilie is <COLON><CAPITAL-D>

The forum makes the changes automatically.... I wish Alex would remove that from the UBB config.

Quote Reply
Re: Yahoo Sub Categories In reply to
Or upgrade to the newest version of UBB that you can disallow smilies to be posted in Threads...

Just my two cents.

Sorry for the interruption.

: )

Regards,

------------------
Eliot Lee....
* Check Resource Center
* Search Forums

Quote Reply
Re: Yahoo Sub Categories In reply to
Hi,

My Links SQL can't find the function
get_sub_categories you used in the mod.
Do you have a newer version of DBSQL?

regards Alexander

Quote Reply
Re: Yahoo Sub Categories In reply to
Same problem here. I have 1.11

------------------
James L. Murray
VirtueTech, Inc.
www.virtuetech.com


Quote Reply
Re: Yahoo Sub Categories In reply to
oops,

sorry about that, I created that sub routine it's based on get_attachments and build_home_page. Please let me know if there are any problems with it. I added it to dbsql. so that's why you can't find it.

sub get_sub_categories {
# --------------------------------------------------------
# This routine gets the list of subcategories
# for displaying on the homepage
#
my ($self, $id) = @_;
$self->connect();

my ($query, $sth, $subcat, @subnames);

$query = qq~
SELECT c.*
FROM CategoryHierarchy AS h, Category AS c
WHERE h.CategoryID = ? AND h.SubCategoryID = c.ID ORDER BY ID
~;
$sth = $DBH->prepare($query) or return $self->error ('CANTPREPARE', $query, $DBI::errstr);
$sth->execute($id) or return $self->error ('CANTEXECUTE', $query, $DBI::errstr);
while ($subcat = $sth->fetchrow_hashref) {
push (@subnames, $subcat);
}
return \@subnames;

}
Quote Reply
Re: Yahoo Sub Categories In reply to
Ok it works, but if I have 20 subcategories on my 2nd teir, it shows them all.

Maybe there is a way to show only 40 charact of the sub categories?


------------------
James L. Murray
VirtueTech, Inc.
www.virtuetech.com




[This message has been edited by Ground Zero (edited February 23, 2000).]