I am starting a new thread, because I still need some help with this, and I hope a new thread will help keep things clearer. (The other thread just confused me). Original Thread:
http://www.gossamer-threads.com/...orum_view_collapsed;
So, here goes:
I'd like to have 3 or so "random" links in each category be displayed. I will have seperate template sets for each category. Alex gave me some code to use that was supposed to limit the categories that the call pulls from, but I haven't gotten it to be successful.
I'd also like to be able to have "links" rotating on the home page, from specified categories.
1) a way to call (from seperate category pages) 3 links from that particular category and display them on the category page.
2) a way to call from the home page (or any other page) 3 random links from defined categories.
Random_Link global Alex gave me to try:
my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
if ($cat_id) {
$sth = $link_db->select ( { CategoryID => $cat_id });
}
else {
$sth = $link_db->select;
}
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }
}
and then to call the random link, place this code on the category page for that particluar category.:
<%Random_Link%>
<%loop Random_Loop%>
<p><%body_font%><A href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><b><%Title%></b><br></A> <%Description%>
[<A href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>">more</A>]</%body_font%>
<br>
<%endloop%>
The problem is, that it still pulls from other categories.
Pweeze help me define this
http://www.gossamer-threads.com/...orum_view_collapsed;
So, here goes:
I'd like to have 3 or so "random" links in each category be displayed. I will have seperate template sets for each category. Alex gave me some code to use that was supposed to limit the categories that the call pulls from, but I haven't gotten it to be successful.
I'd also like to be able to have "links" rotating on the home page, from specified categories.
1) a way to call (from seperate category pages) 3 links from that particular category and display them on the category page.
2) a way to call from the home page (or any other page) 3 random links from defined categories.
Random_Link global Alex gave me to try:
Code:
sub { my $tags = shift;
my $link_db = $DB->table('Links','CatLinks');
my $cat_id = $tags->{Random_CatID};
my $limit = $tags->{Random_Limit} || 3;
my (@output, $sth);
$link_db->select_options ('ORDER BY RAND()', "LIMIT $limit");
if ($cat_id) {
$sth = $link_db->select ( { CategoryID => $cat_id });
}
else {
$sth = $link_db->select;
}
while (my $hash = $sth->fetchrow_hashref) {
push @output, $hash;
}
return { Random_Loop => \@output }
}
and then to call the random link, place this code on the category page for that particluar category.:
Code:
<%set Random_Category = 9%> <%Random_Link%>
<%loop Random_Loop%>
<p><%body_font%><A href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><b><%Title%></b><br></A> <%Description%>
[<A href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>">more</A>]</%body_font%>
<br>
<%endloop%>
The problem is, that it still pulls from other categories.
Pweeze help me define this