I've started a "featured links" mod. What it does is pull a featured link from the category, and display it under the category name on category page listings.
It's bare-bones, but it's fully self contained. I'm posting it here only so that maybe some people will help with this idea... It's easy and flexible to modify. It might be something similar to what you want, but not exactly.
Code:
sub grab_featured_link { ## expects a CategoryID number only
# --------------------------------------------------------
#
my $cat_id = shift; # Contains a vallid categoryID so we are not going to check it.
my $LINKDB = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Links.def";
my $DEBUG_GRAB=0;
print "Content-type: text/html\n\n" if ($DEBUG_GRAB);
my ($cat, $cat_r, $cat_ID, $get_link, $f_link, $output, $offset, $count);
$output = '';
## $get_link = $LINKDB->prepare (" SELECT * FROM Links WHERE CategoryID = ? AND is_Featured = 'Yes' LIMIT 1 "); ## prepare the select statement
$get_link = $LINKDB->prepare (" SELECT * FROM Links WHERE CategoryID = ? AND Priority = 'Yes' LIMIT 1 "); ## prepare the select statement
$get_link->execute ($cat_id); ## execute the select statement to find a featured link.
$f_link = $get_link->fetchrow_hashref || (); ## fetch the returned row, or assign an empty list
if (!$f_link) { ## if there are no featured links, pick a random one
print "There are no featured links <BR>\n" if ($DEBUG_GRAB);
print "The category ID we are checking is ...", $cat_id, "<BR>\n" if ($DEBUG_GRAB);
$get_link = $LINKDB->prepare ( "SELECT COUNT(*) FROM Links WHERE CategoryID = $cat_id"); ## gets all the links
$get_link->execute() or die $DBI::errstr;
$count = $get_link->fetchrow_array;
if ($count) {
print "COUNT IS .... ", $count,"<BR>\n" if ($DEBUG_GRAB);
($count == 1) ? $offset=0 : $offset = int rand ($count - 1) ;
print "The ofset value is .... ", $offset, "<BR>\n" if ($DEBUG_GRAB);
$get_link = $LINKDB->prepare ( " SELECT * FROM Links Where CategoryID = $cat_id LIMIT $offset, 1 ");
$get_link->execute() or die $DBI::errstr;
$f_link = $get_link->fetchrow_hashref;
print "F_LINK is...:", $f_link, "<BR>\n" if ($DEBUG_GRAB);
}
}
$cat = get_category_name($cat_id) ;
## $output .= "Today's Featured Link in <B>$cat</B> is: <BR>\n" if ($f_link); ## debugging flag, mainly
$output .= "Today's Featured Link is:\n" if ($f_link); ## debugging flag, mainly
($f_link) ? $output .= &site_html_link($f_link) : $output .= ''; ## if there are no links at all
return $output;
}
In site_html_print_cat, below the &load_template call, add:
defined $dynamic and $output .= &grab_featured_link ($cat_r->{ID}); ### testing, only with page.cgi though
That's all there is to this mod. It's pretty cool, and you can actually create a new routine, instead of &site_html_link to send the link to, to do custom "short" or "featured" formatting.
PUGDOGŪ PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ