Gossamer Forum
Home : Products : Gossamer Links : Discussions :

link to link's category?

Quote Reply
link to link's category?
hi

i'm using the top 5 global, but what I want to do is make the title link back to the category the link is in, rather than go to the URL of the link.

can anyone tell me how to do that - ie what to stick in the global and what tag goes in the template?

here's the global I'm using...


Code:
sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('include_nav_newlinks_format', $link);
}
return $output;
}



r

Last edited by:

ryel01: Mar 18, 2004, 1:13 AM
Quote Reply
Re: [ryel01] link to link's category? In reply to
you can either add:

Code:

my $catdb = $DB->table('CatLinks', 'Category');
my $catsth = $catdb->select ({ 'CatLinks.LinkID' => $id}, ["Category.Full_Name"]);
$link->{category} = $catsth->fetchrow_array;

to the while loop...

Or create a new global called "category":

Code:
sub {
my $vars = shift;
my $id = $vars->{ID};

my $table = $DB->table('CatLinks', 'Category');
my $sth = $table->select ({ 'CatLinks.LinkID' => $id}, ["Category.Full_Name"]);
my $name = $sth->fetchrow_array;

return $name;
}

Then in your template you can do:

Code:
<a href="<%build_root_url%>/<%category%>/index.html"><%Title%></a>

Philip
------------------
Limecat is not pleased.

Last edited by:

fuzzy logic: Mar 18, 2004, 8:18 AM
Quote Reply
Re: [fuzzy logic] link to link's category? In reply to
Hmmmm... I'm getting a can not compile error. When I blank out the lines it only happens when I uncomment the one in red...

Code:
sub {
# Displays the newest links on the home page.

# Get the link information
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
# Get the links category information
my $catdb = $DB->table('CatLinks', 'Category');
my $catsth = $catdb->select ({ 'CatLinks.LinkID' => $id }, ["Category.Full_Name"]);
$link->{category} = $catsth->fetchrow_array;

$output .= Links::SiteHTML::display ('include_nav_newlinks_format', $link);
}
return $output;
}

r
Quote Reply
Re: [ryel01] link to link's category? In reply to
I assume you have a prefix on your tables? Change

my $catsth = $catdb->select ({ 'CatLinks.LinkID' => $id }, ["Category.Full_Name"]);

to

my $catsth = $catdb->select ({ 'LinkID' => $id }, ["Full_Name"]);

(You only need the table name when there is the same field in more than one table.)


Quote Reply
Re: [afinlr] link to link's category? In reply to
i corrected that line, but am still getting the compile error - any ideas?

Code:
sub {
# Displays the newest links on the home page.

# Get the link information
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
# Get the links category information
my $catdb = $DB->table('CatLinks', 'Category');
my $catsth = $catdb->select ({ 'LinkID' => $id }, ["Full_Name"]);
$link->{category} = $catsth->fetchrow_array;

$output .= Links::SiteHTML::display ('include_nav_newlinks_format', $link);
}
return $output;
}

regan
Quote Reply
Re: [ryel01] link to link's category? In reply to
There are a couple problems with that...

a) although not the cause of the trouble, you really out to make $link local to the while loop.

Code:
while (my $link = $sth->fetchrow_hashref()) {

b) you need to change:

Code:
my $catsth = $catdb->select ({ 'LinkID' => $id }, ["Full_Name"]);

to:
Code:
my $catsth = $catdb->select ({ 'LinkID' => $link->{ID} }, ["Full_Name"]);

c) you may also need to change:
Code:
$output .= Links::SiteHTML::display('include_nav_newlinks_format', $link);

to:
Code:
$output .= Links::user_page('include_nav_newlinks_format', $link);

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] link to link's category? In reply to
 
that worked perfectly - thanks!!!

if you don't mind one more, if I wanted the "URL" to the category instead of the name of the category, how to modify that one?
Quote Reply
Re: [fuzzy logic] link to link's category? In reply to
i checked out the yahoo plugin and found the answer - now it formats the Full_Name into a proper URL back to that category. changes I made in RED - if there's a better way to do the same let me know - thanks for your help! Smile

Code:
sub {

my ($output,$sth);
my $search_db = $DB->table('Links');
my $cat_table = $DB->table('Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while (my $link = $sth->fetchrow_hashref()) {
# Get the links category information
my $catdb = $DB->table('CatLinks', 'Category');
my $catsth = $catdb->select ({ 'LinkID' => $link->{ID} }, ["Full_Name"]);
$link->{category} = $CFG->{build_root_url} . "/" . $cat_table->as_url ( $catsth->fetchrow_array ) . "/" . $CFG->{build_index};
$output .= Links::user_page('include_nav_newlinks_format.html', $link);

}
return $output;
}