K5 Section Stories Box
|
|
By rusty , Section Code [] Posted on Tue Dec 05, 2000 at 12:00:00 PM PST
|
|
Prompted by a request on #kuro5hin, here is the code that creates the left-hand "Section Stories" box on K5. The code follows, feel free to cut and paste. For the template, I use a block called "sec_story_box", which is just the basic container HTML.
I hope that if people have done clever things with output, they'll also post boxes here, so we can all share them. Note the "Boxes" topic. :-)
|
########################
# Section stories box
# From kuro5hin.org
########################
my $content;
####
# order sections:
# I do this manually here so that
# they will appear in the order I want them in.
####
my @sections = qw(
tech
culture
fnp
media
news
internet
op-ed
mlp
Meta
columns );
# How many stories to show from each section?
my $num_stories = 3;
# How many new diaries to show?
my $num_diaries = 25;
####
# Loop through the above array...
####
foreach my $section (@sections) {
# Get the title and sid for the last $num stories
my ($rv, $sth) = $S->db_select({
WHAT => 'sid, title',
FROM => 'stories',
WHERE => qq{section = "$section" AND displaystatus = 1},
ORDER_BY => 'time DESC',
LIMIT => $num_stories});
# Add the link for the section header
$content .= qq{
<B><A HREf="|rootdir|/?op=section;section=$section">$S->{SECTION_DATA}->{$section}->{title}</A>:</B>
<BR>|smallfont|};
# Add the link for each story
while (my $story = $sth->fetchrow_hashref()) {
my $comments = $S->_commentcount($story->{sid});
$content .= qq{
|dot| <A HREF="|rootdir|/?op=displaystory;sid=$story->{sid}">$story->{title}</A>
($comments comments)<BR>};
}
# Add the closing "More..." link
$content .= qq{
<A HREf="|rootdir|/?op=section;section=$section">more...</A>
|smallfont_end|
<P>};
}
####
# New diary list
####
# Get the last $num_diaries Diary entries
my ($rv, $sth) = $S->db_select({
WHAT => 'sid, aid',
FROM => 'stories',
WHERE => qq{section = "Diary" AND displaystatus = 1},
ORDER_BY => 'time DESC',
LIMIT => $num_diaries});
# Add the diaries header link
$content .= qq{
<B><A HREf="|rootdir|/?op=section;section=Diary">New $S->{SECTION_DATA}->{Diary}->{title}</A>:</B>
<BR>|smallfont|};
# Add each new diary link.
# You could select more stuff above and list, eg,
# the title of the diary entry
while (my $story = $sth->fetchrow_hashref()) {
$content .= qq{
|dot| <A HREF="|rootdir|/?op=displaystory;sid=$story->{sid}">$story->{aid}</A><BR>};
}
# Add the "More..." link for diaries
$content .= qq{
<BR><A HREf="|rootdir|/?op=search;type=diary;offset=25">More Diaries...</A>
|smallfont_end|
<P>};
# And return the content, like normal.
return {content => $content};
|
|
Story Views
|
34 Scoop users have viewed this story.
|
|