Gossamer Forum
Home : Products : Links 2.0 : Customization :

Display category number.

Quote Reply
Display category number.
I have set up links to generate .php files. Each file will then have includes, based on the category. What I need to do is use the category id as a value that will then be used within an include. To be honest I have never been strong with Perl. Can someone help me get the value for the category ID on page. For now all i need the the number printed on the category page. I will be able to work the rest out from there.

Thanks in advance.
Quote Reply
Re: [mackuk] Display category number. In reply to
I think this will work...

In site_html_templates.pl, sub site_html_print_cat, find this:

my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);

and add this to it:

my ($url, $numlinks, $mod, $subcat, $category_name, $description, $number, $output, $i);

Then find:

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

and add this under it:

($number) = @{$category{$subcat}}[0];


Then in sub site_html_category, add:

number => $number,

Then use <%number%> in the template to call the category number.
I suggest 'number' instead of 'ID' to avoid potential clashes.
I did not test this. Let me know if it works.Sly


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Display category number. In reply to
Thank you very much for your response. I tried the modifications you suggested, but it still doesn display the value. Having said that it doesnt give an unknown tag error either, so somethign must be right Wink

Im going to spend tonight tryign to work it out, if I manage I will post the solution here, or of you have any other suggestions please feel free to post!

Thanks once again.
Quote Reply
Re: [mackuk] Display category number. In reply to
Hi,

This should work (not the quickest way to do it, as it requires another "opening" of one of the DB files.

1) Open site_html_templates.pl, and add this at the end of the file (just before 1;)

Code:
sub get_cat_id {

my $cname = $_[0];

# return $cname;

my $_id;
open (READIT,"$db_script_path/data/categories.db") || die "Cant read: $db_script_path/data/categories.db . Reason: $!";
while (<READIT>) {
# 0: id | 1: name
my @split = split /\|/, $_;
print qq|foo boo: $split[1] eq $cname <br />|;
if ($split[1] eq $cname) {
$_id = $split[0];
last;
}
}
close(READIT);
print qq|BLA BLA ID: $_id <br/>|;
return $_id;
}

Then, find the site_html_category routine, and add in the bit in bold:

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

return &load_template ( 'category.html', {
catid => get_cat_id($category_name),
date => $date,
time => $time,
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
} );
}

Then, just use the <%catid%> tag where you want the ID number to show :)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display category number. In reply to
I think my way will work, too but the call needs to be made in the subroutine, not from the template. Not knowing what you're wanting to include makes it a guess, but you could add something before the link-listing output (table) like so (site_html_templates.pl):

# Print Header.
$output = qq|<?php\n
include ('../$number.inc')\n
?>\n|;
$output .= qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

...or whatever code you need...


Leonard
aka PerlFlunkie