Gossamer Forum
Home : Products : Links 2.0 : Customization :

Main categorys on all pages instead of only home page

(Page 1 of 2)
> >
Quote Reply
Main categorys on all pages instead of only home page
Is tthere anyone who can tell me how to list the main categories on all the pages instead of the sub-categories like on the category pages
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
You might be able to do that using the Links Tree mod (with some changes) that is in the Resource Center.

I hope this helps.
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
hi you guys.. as you can see on my pages..

http://www.pdamania.com

if you go up a category there is that list of categories underneath the search thing..all you need to do now if just urlencode the category and your done.. plus it isn't a long subroutine.. i recall about 15 lines..

jerry
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
hehe.. i just realized what i was missing..

HOW TO DO IT..

well.. the last time i gave someone the code.. they were using templates and said it didn't work.. this code goes in your site_html.pl or site_html_templates.pl depending on what you use..

Code:
sub site_html_category_list {
my ($category) = @_;
my ($suburl, $output);

foreach (sort keys %category) {
next unless ($_ =~ m,^([^/]*)$,);
if ($category ne $_) {
$suburl = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<a href="$suburl">$_<br>\n~;
}
}
return $output;
}

and then in site_html.pl.. wherever you want to print it.. the code is usually..

Code:
~; $output .= &site_html_category_list ($category_name_escaped); $output .= qq~

i think to do it with templates you should just be able to put this in the load template area of the template you are using.. (category template hopefully)

Code:
category_list => &site_html_category_list ($category_name_escaped),

and in the thing.. <%category_list%>

remember.. the template user said it didn't work.. but that most probably cause the hash

%category doesn't get to templates.. dunno

if you can get it to work with templates.. you will save me some time to explain to him Smile

jerry

[This message has been edited by widgetz (edited August 09, 1999).]

[This message has been edited by widgetz (edited August 09, 1999).]

[This message has been edited by widgetz (edited August 09, 1999).]

[This message has been edited by widgetz (edited August 09, 1999).]
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Actually, the suggestion Bobsie has is quite simple,

I've been thinking of that also. I have picked up the tree mod and let it write a file without menu's and search box. Take a look at http://www.free4u2.com/tree.html

It should be a piece of cake to use SSI (if your server supports it) and include this on all your pages.

The advance is that all the pages are updated whenever you add a category.

If you need more info on how to adjust the subroutine which builds the links tree let me know.

Jeroen

------------------
Free 4U2: a searchable directory of free stuff
http://www.free4u2.com

When something does not function properly, hit it hard.....
.....When it breaks it had to be replaced anyway.


Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
I'd like to know how you cleaned up the build_tree_page sub-routine in your nph-build.cgi??

I worked on the Link Tree mod last night and it came out like doggy doo. Frown I hacked the html codes as best as I could and all I got was an indented list of categories and sub-categories that wrapped all over the page.

Please share your ideas (or codes) of how to clean up the build_tree_page sub-routine.

Also, your (and Bobsie's) idea of inserting the "tree" via SSI (Server Side Includes) is a great idea. Since there is currently NO template for the Tree page, using it as SSI is no problem.

Regards,


------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Well basicly what I did was this:

I took my own nph_build.cgi and inserted this in sub build_all

Code:
# Create Tree Page
$use_html ?
print "Building <A HREF=\"$build_root_url/tree.html\">Tree</A> Page . . .\n" :
print "Building Tree Page . . .\n";
&build_tree_page;
print "Done\n\n";

I inserted behind the what's cool routine, but it could be anywhere within that routine.
CAUTION: When you use staggered build you have to insert something similar in that routine. You could probably copy and paste the what's cool part changing the call for the subroutine.

And here's my sub build_tree_page:

Code:
sub build_tree_page {
# --------------------------------------------------------
# This routine builds a tree from all links/categories

my ($cat, $url, $dir, @related, $relation, $page_num, $next_page, $numlinks);
my ($linkstree, $output, @categorylist, $depth_old, $depth_new);
local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped);
local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $next, $prev);

# set linkstree to 0 if you want only a tree off all categories
# set linkstree to 1 if you want a tree off all categories and links
$linkstree = 0;

$depth_old = 0;
$url = "$build_root_path/tree$build_extension";
open (CAT, ">$url") or &cgierr ("unable to open category page: $url. Reason: $!");

# Go through each category and build the appropriate page.
CATEGORY: foreach $cat (sort keys %category) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)

# We set up all the variables people can use in &site_html.pl.
($description, $related, $meta_name, $meta_keywords, $header, $footer) = @{$category{$cat}}[2..7];

$title_linked = &build_linked_title ($cat);
$title = &build_unlinked_title ($cat);
$total = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$category_name = $cat;
$category_name_escaped = &urlencode ($cat);
$category_clean = &build_clean ($cat);

$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
@categorylist = split (/\//, $cat);
$depth_new = $#categorylist;
$links = "";
if ($depth_new < $depth_old) {
for ($i = 0; $i <= ($depth_old - ($depth_new + 1)); $i++) {
$links .= "\n";
}
}

$links .= qq~\n<br><font face=Geneva,Helvetica,Arial size=2><strong><a href="$build_root_url/$cat/">$title</a></strong></font>~;
if ($linkstree == 1) {
for ($i = 0; $i < $numlinks; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}
$links .= "\n";
}

print CAT $links;
$depth_old = $depth_new;
}

close CAT;
}

All I need now is someone who is willing explain to me how I can get the subcategories to list by their own name intead of being preceded with the category they belong to. For an example visit http://www.free4u2.com/tree.html

That's about it.

Let me know if someone can help me with the subcategory problem.

Jeroen


------------------
Free 4U2: a searchable directory of free stuff
http://www.free4u2.com

When something does not function properly, hit it hard.....
.....When it breaks it had to be replaced anyway.


Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Jeroen,

Ah ha! I see one thing that I could use that may help me clean up the output. Adding the <br> may help. Also adding in $links .= &site_html_link (%tmp); may help.

Thanks!

About cleaning up the sub-categories...I would also like to see how that can be done.

I would like to see the output like the following example (in a tabular format):

Main Category A Main Category C
* Sub-Category1 * Sub-Category1
* Sub-Category2 * Sub-Category2

Main Category B Main Category D
* Sub-Category1 * Sub-Category1
* Sub-Category2 * Sub-Category2

It would help because I have over 400 categories and sub-categories. One thing I noticed is that the file is quite large and you have to scroll many screens to reach the bottom.

If anyone can come up with a modification for this, I would greatly appreciate it. Smile

I am trying to use the Links Tree mod as a "Site Map" page.

Regards,
------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 09, 1999).]
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
widgetz,

I am confused here. Does the build_tree_page sub-routine (with the Links Tree Mod) interact with the site_html_category_list sub-routine?? I thought you had to edit the codes in the build_tree_page sub-routine only to create a different look for the "tree.html" page.

Thanks.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
no.. i thought you guys wanted to display the main categories on any page.. that's how you do it..

it works on it's own.. only a few lines Smile

jerry
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Thanks, Widgetz for explaining yourself. Smile
This Thread is dedicated to the discussion of modifying the Links Tree Mod or at least that is what I thought it was. Smile

It is a good thing you let us know that the mod you've provided is NOT for the build_tree_pages. If you know of a way to edit the build_tree_pages in the "Link Tree" Mod, please feel free to post codes or suggestions.

Thanks,


------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
uhh. i'm rereading what griff said and i beleive i wasn't offtopic.. he wants to list the main categories on all the pages.. and that is what mine does...

i think it was you that started the topic about link tree.. am i wrong? Smile

jerry
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Hi, I maight be a bit late to help, because you may have tried the previous methods. But if you take a look at my page at http://zoneonline.net/links you'll see what I've done for this. I didn't use the build_tree script. Instead I made changes to the nph-build file to create a header and footer file that can later be put together with SSI on any of the pages I want. This gave me a bit more flexibility to changing my index file since it now does not depend on nph-build. Also since the header and footer are created by the build script, all the pages share consistency. If this is what you are trying to do let me know, and I'll show you the changes I made.
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
HOW MANY TIMES DO I HAVE TO SAY THIS..

mine does the same exact thing.. except it doesn't need SSI.. so it loads faster..

ok Smile

jerry
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Sorry widgetz, I sort of only perused over the script you posted. But you are right it would be faster and I would regain control over the titles of the pages.
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Thanks you all, this is what i was looking for. It seems to work well, if i could only get the new and pop next to it when there is something new in the category
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
 
Quote:
the last time i gave someone the code.. they were using templates and said it didn't work

Jerry, your code to print the categories on all of the pages works with templates. Smile

How do I get the number of links for each category to print next to the category list?

Like this:
CategoryA (numlinks)
CategoryB (numlinks)
..etc.

Thanks Smile
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Code:
sub site_html_category_list {
my ($category) = @_;
my ($suburl, $output);
foreach (sort keys %category) {
next unless ($_ =~ m,^([^/]*)$,);
if ($category ne $_) {
$suburl = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<a href="$suburl">$_</a> (~ . $stats{$_}[0] . qq~)<br>\n~;
}
}
return $output;
}

jerry
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Well, it seams that my english is not good enought.

Where excatly do you pout the code to perform on a templated site ?

Main Category
Subcat1, Subcat2, Subcat3
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Hi Guys.

Well, I've been attempting to pull this off!

I have done the following,

--- -- -- ---
Added to the bottom of[site_html_templates.pl]
--- -- -- ---

#New Addition for Subcategories on Each Page
sub site_html_category_list {
my ($category) = @_;
my ($suburl, $output);
foreach (sort keys %category) {
next unless ($_ =~ m,^([^/]*)$,);
if ($category ne $_) {
$suburl = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<a href="$suburl">$_<br>\n~;
}
}
return $output;
}
# End of Code Addition


Now, I am using Templates, so I *attempted* to add the following to: [category.html]

--- -- -- ---
category_list => &site_html_category_list ($category_name_escaped),
--- -- -- ---

That didn't work, so I tried:

--- -- -- ---
<%~; $output .= &site_html_category_list ($category_name_escaped); $output .= qq~%>
--- -- -- ---

And that didn't work either.

Now, I know I'm missing a command somewhere!
1. What did I miss?
2. What *exactly* am I suppose to add?
3. Where *exactly* am I suppose to put it?

Again, and always, thanks to all!
JbA
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
I've tried Widgetz's code for displaying the category list on all the categroy pages. It is working except for the display of the category includes the "_" in the category name that is displayed. Any ideas on what to change (using templates)??

Thanks
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Try adding the following codes to the top of the sub site_html_category routine:

Code:
my $clean_category = &build_clean($category);

BEFORE the loading template codes.

Replace the following codes:

Code:
category_list => &site_html_category_list ($category_name_escaped),

WITH the following:

Code:
category_list => &site_html_category_list ($clean_category),

Don't gaurantee this will work.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Thanks Eliot, but it didn't change anything. An example of what is happening is at http://www.freequest.com/Catalogs/

Any other ideas??

SteveK
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Hello all,

I have been trying on my own to generate a menu of all categories and subcategories for use on any page that I wish as an SSI.

I scanned over this discussion, and didn't see anybody mention the idea that I had, so I thought I'd share my idea with the group. Please reply with your questions/recommendations.

I am only a dabbler in Perl so please let me know if I made any mistakes.

It works perfectly except for the sort command. It just doesn't sort?!? Wink

The main idea is to use the categories.db file as the source for my menu.

Code:
#!/usr/local/bin/perl

##########
#Require Files
##########
require "/admin/links.cfg";

##########
#Assign Database File
##########
$db = "$db_script_path/data/categories.db";

##########
# Select Output File
##########
open (OUT, ">all-categories.incl") or
die "Couldn't open all-categories.incl \n";

select (OUT);

open (DB, $db) or
die "Couldn't open $db \n";

##########
# Search Database and Create @all_cat
##########

while (<DB> ) {
$current = $_;
chomp ($current);
($garbage1 , $sub_cat , $garbage2) = split (/\|/ , $current , 3);
push (@all_cats , $sub_cat);

}

close (DB);

sort @all_cats;

##########
# Create Category List
##########

foreach $cat (@all_cats) {
if ($cat !~ m/\//) {
$cat_name = $cat;
$catname =~ s/_/ /g;
print "<b> \n";
print "<a href=\"$build_root_url/$cat\">$cat_name</a> \n";
print "</b> \n";
print "<br> \n";
}
else {
($garbage3, $sub_name) = split (/\// , $cat , 2);
$sub_name =~ s/_/ /g;
print "<a href=\"$build_root_url/$cat\">$sub_name</a> \n";
print "<br> \n";
}
}

close (OUT);

Again, please let me know what you think.

Dan

------------------
------
Get your Free Subscription to "Making Money with Affiliate Programs"

creativeopportunity-subscribe@topica.com
Quote Reply
Re: Main categorys on all pages instead of only home page In reply to
Hi Jeroen,

I try to find http://www.free4u2.com/tree.html but there is not this fail :(

> >