Gossamer Forum
Home : Products : Links 2.0 : Customization :

How can I add diffrent image before category name?

Quote Reply
How can I add diffrent image before category name?
Hello all,
Could you please tell me how can I add a diffrent image next to (before) each category and subcategory names?
I could not find this mod anywhere.

Thank you in advance for your help.
Mark

Quote Reply
Re: How can I add diffrent image before category name? In reply to
1) Add a field in the category.def file called CatImage.

2) Then update your categories.db with the upgrade.pl script which is referenced many times in this forum.

3) Then edit the codes in the sub build_category_pages in the nph-build.cgi around where #site_html.pl text is found. You will need to add the new field and also increase the number 7 to 8.

4) Then in your sub site_html_category routine, add the following tag definition:

Code:

CatImage => $catimage


NOTE: $catimage is what you will add in the sub build_category_pages. Look for $header codes as a model in that subroutine.

5) Then you will have to edit the sub site_html_print_cat to include the $catimage before the $category_name variable.

6) If you want the image to also appear before category names in the Category pages, add the following tags in the category.html file:

Code:

<%if CatImage%>
<%CatImage%>
<%endif%>


Regards,

Eliot Lee
Quote Reply
Re: How can I add diffrent image before category name? In reply to
Hello Eliot,
As you instructed, I have made the following modifications to my code,
in addition to what you have stated above, but, unfortunately, it did not
work right; specially, that I have the non-English mod installed which confused me.

What I am trying to do is to have the FLAG of each country to appear in front of that country name.
Please note that the country names are SUB CATEGORIES of the main category that is called COUNTRIES.

So, how can I proceed? or can I make the subcategory names accept images in their names. How?


Thank in advance for all your help..
Regards..
Mark



Code:
*****************************************
*****************************************
*****************************************


in this file I added the following field so it appears before the category/subcategory names


category.def
============

%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
CatImage => [1, 'alpha', 10, 100, 0, '', ''],
Name => [2, 'alpha', 40, 75, 1, '', '^[\w\d,\&\'\@/_-]+$'],
Description => [3, 'alpha', '40x3', 500, 0, '', ''],
Related => [4, 'alpha', 0, 255, 0, '', ''],
'Meta Description' => [5, 'alpha', 40, 75, 0, '', ''],
'Meta Keywords' => [6, 'alpha', 40, 75, 0, '', ''],
Header => [7, 'alpha', 40, 75, 0, '', ''],
Footer => [8, 'alpha', 40, 75, 0, '', ''],
Nonenglish => [9, 'alpha', 40, 75, 0, '', '']

);


*****************************************
*****************************************
*****************************************


Since I have installed the non-english mod, then things got more diffecult to follow.
I am not sure where exactly I should place the catimage!!!

nph-build.cgi
=============
sub build_category_pages {
# --------------------------------------------------------
# This routine builds all the category pages. Each category uses
# the same template which is defined in &site_html_category.

my $build_single = shift;

my ($cat, $url, $dir, @related, $relation, $page_num, $next_page, $numlinks);
local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped);


# ***************************************** nonenglish modification - begin ****************
local ($catimage, $description, $related, $meta_name, $meta_keywords, $header, $footer, $nonenglish, $next, $prev);
# ***************************************** nonenglish modification - end ******************
# 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? =)
next CATEGORY if ($build_single and ($build_single ne $cat));

$url = "$build_root_url/" . &urlencode($cat) . "/";
$use_html ?
print qq|Building Category: <A HREF="$url" TARGET="_blank">$cat</A>\n| :
print qq|Building Category: $cat\n|;
print "\tSubcategories: " . ($#{$subcategories{$cat}} + 1) . "\n";
print "\tLinks: " . (($#{$links{$cat}}+1) / ($#db_cols+1)) . "\n";

# Let's make sure the directory exists, build it if it doesn't.
$dir = &build_dir ($cat);
print "\tDirectory: $dir\n";
print "\tFilename : $dir/$build_index\n";

# We set up all the variables people can use in &site_html.pl.
# ***************************************** nonenglish modification - begin ****************
($catimage, $description, $related, $meta_name, $meta_keywords, $header, $footer, $nonenglish) = @{$category{$cat}}[2..9];
# ***************************************** nonenglish modification - end ******************
# Calculate the related entries and put in a <LI> list.
@related = split(/\Q$db_delim\E/, $related); $related = "";
foreach $relation (@related) {
$related .= qq|<li><a href="$build_root_url/|;
$related .= &urlencode($relation);
$related .= qq|/$build_index">|;
# ***************************************** nonenglish modification - begin ****************
$related .= &kategorie_title_mb($relation);
# ***************************************** nonenglish modification - end ******************
$related .= "</a></li>";
}

# Get the header and footer from file if it exists, otherwise assume it is html.
if ($header && (length($header) < 20) && ($header !~ /\s+/) && (-e "$db_header_path/$header")) {
open (HEAD, "<$db_header_path/$header") or &cgierr ("Unable to open header file: $db_header_path/$header. Reason: $!");
$header = "";
while (<HEAD>) {
$header .= $_;
}
close HEAD;
}
if ($footer && (length($footer) < 20) && ($footer !~ /\s+/) && (-e "$db_footer_path/$footer")) {
open (FOOT, "<$db_footer_path/$footer") or &cgierr ("Unable to open footer file: $db_footer_path/$footer. Reason: $!");
$footer = "";
while (<FOOT>) {
$footer .= $_;
}
close FOOT;
}



etc...



*****************************************
*****************************************
*****************************************


In this one I am not sure on the position of catimage!!


site_html_templates.pl
======================

sub site_html_category
#----------------------------------
.
.
return &load_template ( 'category.html', {
date => $date,
time => $time,
CatImage => $catimage,
category => $category,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );



sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#

my (@subcat) = @_;
# ***************************************** nonenglish modification - begin ****************
my ($url, $numlinks, $mod, $subcat, $catimage, $category_name, $description, $output, $i, $nonenglish);
# ***************************************** nonenglish modification - end ******************
my ($half) = int (($#subcat+2) / 2);
# Print Header.
$output = qq|<div class="margin"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

etc...


*****************************************
*****************************************
*****************************************





Quote Reply
Re: How can I add diffrent image before category name? In reply to
One big step that you are MOST LIKELY forgetting is that you need to UPDATE your EXISTING categories.db file with the new field you added in the category.def file.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: How can I add diffrent image before category name? In reply to
Thank you Eliot for your help.
Finally, I found two mods in this forum that do what I want them to do: one to place a different image next to each category and subcategory, and the other one is to place a logo (from the modifications) next to each link.

Thank you for all your help.
Mark. E.

Quote Reply
Re: How can I add diffrent image before category name? In reply to
Mark1

what are the links/threads where you found those two mods?



Quote Reply
Re: How can I add diffrent image before category name? In reply to
Hello

There are different mods in ressource center :

for the first question :
Multiple categorie templates (i'm not sur of the mod's name)

for the second :
Yurik mod for pic
http://www.gossamer-threads.com/scripts/resources/Detailed/845.html

Or priority and logo mod (not sure again Wink)

Ciao


Quote Reply
Re: How can I add diffrent image before category name? In reply to
hey thanks jude

Quote Reply
Re: How can I add diffrent image before category name? In reply to
U're welcome Laugh

Quote Reply
Re: How can I add diffrent image before category name? In reply to
Uh...Yurik's Pic Mod is for LINKS database (links.db) NOT CATEGORIES (categories.db)!

Regards,

Eliot Lee
Quote Reply
Re: How can I add diffrent image before category name? In reply to
Hello

I know Eliot, but he told us
how :
- to have a image for each category
- to have a logo near each links...

So Yurik mod is the good mod for the second option isn't it?

Ciao

Quote Reply
Re: How can I add diffrent image before category name? In reply to
Yes...the second option, but NOT the first and THAT is WHY I re-posted codes that I've posted before for ADDING icons/images for CATEGORIES. Tongue

Regards,

Eliot Lee
Quote Reply
Re: How can I add diffrent image before category name? In reply to
I can't seem to get this to work, either for a pic field or any other field that I add to category.def.

1. I added a field to category.def
2. Updated sub build_category_pages in nph-build
3. Added the new field to sub site_html_category and sub site_html_print_cat in site_html_templates.pl
4. And added the extra field in categories.db

But I can't seem to pull the field data into the category output during build for some reason.

I think I got all the steps. Is there something else that I should be trying?

Thanks for any help.

DT



Quote Reply
Re: How can I add diffrent image before category name? In reply to
Please try this one:
http://gossamer-threads.com/...pl?ubb=004795:Forum3
as this is the one that I have used and it works fine.

Important note:
I think the images should be in gif format and NOT jpg format in order to appear next to the category name.
Another thing, my flags, I have created them from scratch and therefore they are copyrighted.
Also, you need to add the new variable in your category.html to be able to see it.

good luck..
Mark


Quote Reply
Re: How can I add diffrent image before category name? In reply to
Thanks very much, Mark1. I see that there is another early riser like me around here, or is it that you never went to sleep, like me, too, sometimes.

I'll try what's in the thread you mentioned, but I am also concerned in general about how contents of a new field in categories.db gets transferred to the output page. The method mentioned by AnthroRules should work for pretty much any added field. So, I can't understand why I'm having trouble.

I'm trying out junko's category template code - http://www.gossamer-threads.com/...&part=1&vc=1 - so that the cat output can be customized with a template (including pics, if I can figure this out), and the default system that junko has working includes, for example, the description field. So, I'm wondering, "How does the data from the description field in categories.def get successfully pulled over but the new CatImage field is not?"

Anyway, that's where I am. I appreciate your super early response and suggestion. Thanks Smile

DT

Quote Reply
Re: [DogTags] How can I add diffrent image before category name? In reply to
i have also tested this modification every thing works fine it is working on template like

<%if CatImage%> <%CatImage%> <%endif%>

it works

but when we call it in the sub site_html_print_cat to include the $catimage before the $category_name variable it gives blank results

i have checked many time could not understand why image is not coming before the catagoery
Megrisoft
Web Hosting Company
India Software Company
SEO Company


Quote Reply
Re: [megri] How can I add diffrent image before category name? In reply to
Post the codes you are using in the sub site_html_print_cat routine in your site_html_templates.pl file.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] How can I add diffrent image before category name? In reply to
thanks for prompt support and reply

follwoing changes i made in site_html_templates.pl

sub site_html_category {
# --------------------------------------------------------
# This rountine will build a page based for the current category.

return &load_template ( 'category.html', {
date => $date,
time => $time,
category => $category,
category_title => $category_title,
CatImage => $catimage,
links => $links,
title_linked => $title_linked,
title => $title,
total => $total,
grand_total => $grand_total,
category_name => $category_name,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
description => $description,
meta_name => $meta_name,
meta_keywords => $meta_keywords,
header => $header,
footer => $footer,
prev => $prev,
next => $next,
related => $related,
build_links_per_page => $build_links_per_page,
%globals
} );
}


---------------------------------
here I am using yahoo sub cat mod also


sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#

my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $catimage, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="99%" border="0" cellspacing="3" cellpadding="3"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];

# 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 ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|$catimage<dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<img BORDER="0" SRC="http://www.ambushaa.com.com/images/new.gif">| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
$sub_length = "";
$output .= qq|<small>|;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); }
else { $subcategory_name = &build_clean($subcatsub); }

$sub_length .= qq|, | if ($description =~ /1$/ && $v ne "0");
$sub_length .= qq|$subcategory_name| if ($description =~ /1$/);

if ($description =~ /1$/ && length($sub_length) > $subcat_length) {
$output .= qq|...|;
last;
}
else {
$output .= qq|, | if ($description =~ /1$/ && $v ne "0");
$output .= qq|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| if ($description =~ /2$/ || $v eq "0");
$output .= qq|&nbsp;&nbsp;| if ($description =~ /2$/);
$output .= qq|<a href="$suburl">$subcategory_name</a>|;
$v++;
}
}
$output .= qq|</small>|;
}
else {
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
$sub_length = "";
$output .= qq|<small>|;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); }
else { $subcategory_name = &build_clean($subcatsub); }

$sub_length .= qq|, | if ($description =~ /1$/ && $v ne "0");
$sub_length .= qq|$subcategory_name| if ($description =~ /1$/);

if ($description =~ /1$/ && length($sub_length) > $subcat_length) {
$output .= qq|...|;
last;
}
else {
$output .= qq|, | if ($description =~ /1$/ && $v ne "0");
$output .= qq|<br>| if ($description =~ /2$/ || $v eq "0");
$output .= qq|&nbsp;&nbsp;| if ($description =~ /2$/);
$output .= qq|<a href="$suburl">$subcategory_name</a>|;
$v++;
}
}
$output .= qq|</small>|;
}
else {
$output .= qq|<dd><span class="descript">$description</span></dd>| if (!($description =~ /^[\s\n]*$/));
}
}
$output .= qq||;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}
Megrisoft
Web Hosting Company
India Software Company
SEO Company


Quote Reply
Re: [megri] How can I add diffrent image before category name? In reply to
dear Heckler
i have posted the

sub site_html_print_cat

please reply
Megrisoft
Web Hosting Company
India Software Company
SEO Company


Quote Reply
Re: [Heckler] How can I add diffrent image before category name? In reply to
dear Heckler
i have posted the

sub site_html_print_cat

please reply
Megrisoft
Web Hosting Company
India Software Company
SEO Company