Gossamer Forum
Home : Products : Links 2.0 : Customization :

Random links in category

Quote Reply
Random links in category
Hello

My need is to build a new page for every category, which contains 3 random links from that category. I have pulled the code below somewhere in the forum, but this one takes in the consideration only the new links. Can somebody help me to hack this code, so that it picks 3 random links from that category?

Thanks!

Walter



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, $prev_page, $next_page, $numlinks);
local ($category, $links, $title_linked, $title, $total, $category_name, $category_name_escaped);
local ($description, $related, $meta_name, $meta_keywords, $header, $footer, $next, $prev, $image, $left, $right, $adv_side, $advzone120);
# 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));

######### CODE TO BE MODIFIED?
my $c = 1;
$links_new=$links_out="";
category: foreach $category (sort {$b <=> $a} keys %new_links) {
LINK: for ($i = 0; $i < ($#{$new_links{$category}}+1) / ($#db_cols + 1); $i++) {
%tmp = &array_to_hash ($i, @{$new_links{$category}});
$links_out{$category} .= &site_html_link (%tmp) . "\n";
}
}
foreach $category (sort {$b <=> $a} keys %links_out) {
if ($cat eq "$category"){
$links_new .= $links_out{$category};
last if ($c > 10);
$c++;
} }
####################
Walter Aresca
http://www.gratis.it