Gossamer Forum
Home : Products : Links 2.0 : Customization :

Related Links, a bit like related categories

Quote Reply
Related Links, a bit like related categories
When the admin is adding/editing categories he can choose related categories. How can I allow the admin to also add related links to a link and display them under the link?

Simon Dyson

Quote Reply
Re: Related Links, a bit like related categories In reply to
It would not seem practical to display related links in the main directory pages. Instead, I would put them in the details page.

I don't know if this will work or not so better keep a backup ready...

1) In links.cfg, add a field called 'Related'.
2) In site_html_templates.pl, sub site_html_detailed
add:
Code:
@rel = split(/~/, $rec{'Related'});
foreach $related_link (@rel) {
my (%rel) = &get_record ($related_link);
$related .= &site_html_related_link (%rel);
}
after:
Code:
my %rec = @_;
then add:
Code:
related => $related,
before:
Code:
%rec,
3) In site_html_templates.pl
add:
Code:
sub site_html_related_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rel = @_;

# Set new and pop to either 1 or 0 for templates.
($rel{'isNew'} eq 'Yes') ? ($rel{'isNew'} = 1) : (delete $rel{'isNew'});
($rel{'isPopular'} eq 'Yes') ? ($rel{'isPopular'} = 1) : (delete $rel{'isPopular'});

return &load_template ('link_related.html', {
detailed_url => "$db_detailed_url/$rel{'ID'}$build_extension",
%rel,
%globals
});
}
4) Create a new template called 'link_related.html' and upload to your template directory.
5) From the admin program, you can now enter link ID's seperated by a '~' in a text field. I don't think you'd want a select list...

--Drew
Quote Reply
Re: Related Links, a bit like related categories In reply to
Thanks Drew,

that all sounds pretty straight forward, other than I may have problems setting up the template in site_html.pl (I don't use templates)

Simon

Quote Reply
Re: Related Links, a bit like related categories In reply to
Okay...
1) Same as previous instructions.
2) Add the $related variable to $output in site_html_detailed where ever you want it displayed.
3 & 4) Make a copy of site_html_link, and change all references of $rec to $rel, and %rec to %rel.

(Now, I've never actually used site_html.pl, so this is just a guess based on the few times I've looked at it.)

--Drew
Quote Reply
Re: Related Links, a bit like related categories In reply to
Thanks again Drew!

Simon

Quote Reply
Re: Related Links, a bit like related categories In reply to
Hi, Simon

Did you get this to work?

kjellkk and I have tried it - http://www.gossamer-threads.com/...w=collapsed&sb=5, but we have problems building past the first detailed page that has related links on it. For example, if I have 100 detailed pages, and the first one has related links on it, the build detailed function dies right after the first detailed page. However, nph-build continues to build the rest of the site without a hitch.

How's is working for you? Can we see it on your site? Any suggestions on how to get it to work? I'm using templates, and I think kjellkk is, too.

Thanks so much.

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
I never guarenteed that hack would work Smile

Try turning off details and use dynamic details via info.cgi or detail.cgi.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Related Links, a bit like related categories In reply to
No problem, Drew! I'm happy that you made the suggestion and got this concept rolling. I think it could be pretty neat. Hopefully, with a little more hacking, it can get working. Thanks for your help! Smile

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
Okay, there are two things not working with this:

1. The building of static detailed pages stops after the first one that has Related links
2. The script is not grabbing the template used for Related links

Here's my code in sub site_html_detailed
In Reply To:
sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;
########### BEGIN PRINTCAT ##########
my $printcat = shift;
my $clean_category = &build_clean($rec{'Category'});
$printcat = qq~$clean_category~;
######### END PRINTCAT ##############
##### BEGIN RELATED ITEMS CODE ######
@rel = split(/~/, $rec{'Related'});
foreach $related_link (@rel) {
my (%rel) = &get_record ($related_link);
$related .= &site_html_related_link (%rel);
}
####### END RELATED ITEMS CODE #######
######## BEGIN WEBRING MOD PART 4 #########
$ring_links_details = $ring_links{$rec{'ID'}};
########## END WEBRING MOD PART 4 ########
return &load_template ('detailed_static.html', {
total => $total,
Total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
Title_Link => $title_linked,
Title_link => $title_linked,
prev_id => $ring_links_details->{prev_id},
next_id => $ring_links_details->{next_id},
printcat => $printcat,
category_name_escaped => $category_name_escaped,
category_clean => $category_clean,
related => $related,
%rec,
%globals
} );
}
What else is needed to get the script to capture the template?

Thanks.

Quote Reply
Re: Related Links, a bit like related categories In reply to
I don't know if this would fix the problem but try adding:
Code:
$related = "";
above
Code:
foreach $related_link (@rel) {
so that $related doesn't append indefinately...

Why do you have three tags for $title_linked?

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Related Links, a bit like related categories In reply to
Hi Drew

I have the 3 title_linked things because somewhere along the way I got the idea that if I screw up the spelling on some of the template pages that it would still work. I gotta clean up some of this stuff...

I'll give the extra code for the related links a try and get back to you. Thanks so much for your help. Smile

Best...
DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
Hi Drew

I tried the extra code that you suggested, but no luck. The build of the detailed pages still stops right after the first detailed page with related links on it.

However, I found that if I uninstalled Loopy's AltCat mod - http://www.online-sweepstakes.com/links-mods/ - and Joker's Join Mod - http://www.gossamer-threads.com/...ew=&sb=&vc=1 - (which combined Bobsie's Exclude Mod, Loopy's AltCat Mod, and Elms' code to add the AltCat to the add.html form - http://www.gossamer-threads.com/...ew=&sb=&vc=1), I found that the Related Links template was working okay.

So, the only problem remaining is building ALL detailed pages if ANY have Related Links.

Does Related Links work for you?

Thanks.

DT


Quote Reply
Re: Related Links, a bit like related categories In reply to
Just pulling this to the top. Anyone have any luck with this one?

Many thanks.

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
I was wondering if anyone made a related links modification that works with a pull-down menu just like related category. (I don't have a lot of links so the list would not be to big to load!)

Quote Reply
Re: Related Links, a bit like related categories In reply to
Hi, just bumpin 'er up to see if anyone might have any thoughts.

Thanks.

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
Resurrection...

The problem is that the building of detail pages quits once the first detail page with related links is built.

Smile

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
I give up.

To be honest I haven't got a clue what is causing it to halt the build process.

Maybe Glenn or Eliot could take a look...

--Drew
Quote Reply
Re: Related Links, a bit like related categories In reply to
Does it halt for you, too, junko, or might it be something quirky with the scripting of the few of us who are having probs?

If it's not halting for you, then I know it's on my end.

Thanks!

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
I *never* installed this hack. It was a suggestion, never implied or directly expressed to be functional by any means. I do not see anything syntaticly incorrect with the provided code...

ug... one last try:

Code:
my @related = split /\~/, $rec{'Related'};
my $related = '';
foreach my $id (@related) {
my %rel = &get_record ($id);
$related .= qq|<li><a href="$db_script_url/jump.cgi?ID=$rel{'ID'}">$rel{'Title'}</a>\n|;
}
print $related;
--Drew
Quote Reply
Re: Related Links, a bit like related categories In reply to
Just gave that code a quick test and had a similar problem of building only one detailed page. I seem to remember having a similar problem after I hacked the detailed sub to build "comments" a while back. Anyway just a suggestion but shoving the code into nph_build.cgi instead seems to work so in the build detailed sub you'd have:

sub build_detailed_view {
# --------------------------------------------------------
# This routine build a single page for every link.
#
my (@values, $id, %rec, %rel, $related, $count);
if ($build_detail_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
print "\t";

open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name. Reason: $!");
LINE: while (<DB>) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$id = $values[$db_key_pos];
%rec = &array_to_hash (0, @values);
$title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}");


$related = "";
@rel = split(/~/, $rec{'Related'});
foreach $related_link (@rel) {
my (%rel) = &get_record ($related_link);
$related .= &site_html_related_link (%rel);
}

open (DETAIL, ">$build_detail_path/$id$build_extension") or &cgierr ("Unable to build detail page: $build_detail_path/$id$build_extension. Reason: $!");
print DETAIL &site_html_detailed (%rec, $related);
close DETAIL;
$use_html ?
print qq~<a href="$build_detail_url/$id$build_extension" target="_blank">$id</a> ~ :
print qq~$id ~;
(++$count % 10) or print "\n\t";
}
close DB;
print "\n";
}


Then in site_html_templates use:


sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#
my %rec = @_;

return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,
related => $related,
%rec,
%globals
} );
}


Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links
Quote Reply
Re: Related Links, a bit like related categories In reply to
No Luck, glennu. It crapped out again. Thanks for trying.

DT

Quote Reply
Re: Related Links, a bit like related categories In reply to
Yeah sorry, can't offer any more suggestions as it seemed to work for me.

Good Luck!

Glenn
Host Links
http://cgi-resource.co.uk/links