forked from bricoleurs/templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalso_on_this_topic.mc
74 lines (51 loc) · 1.93 KB
/
also_on_this_topic.mc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%doc>
=head1 NAME
also_on_this_topic - Returns a list of related stories by a matching secondary category
=head1 VERSION
1.0
=head1 SYNOPSIS
To come...
=head1 DESCRIPTION
To come...
=head1 AUTHOR
Brad Harder <[email protected]>
=head1 COPYRIGHT AND LICENSE
To come...
=cut
</%doc>\
<%args>
@secondary_categories
$skip_story_id => undef
$max_return => 5
</%args>
<%perl>
# setting max_return to "0" (either by passing in value when calling, or adjusting above), means return everything.
my $count_returned=0; # default to returning everything found.
my $need_to_print_header = 1; #header for returned article stubs.
my $return_limit; #this is passed to the Bric::Biz... call -- requires special handling.
if(0==$max_return){ #unlimited
$return_limit = 0;
}else{
$return_limit = $max_return + 1; #allow for potential match on a story ID we won't use
}
foreach my $secondary_cat (@secondary_categories){
my $secondary_cat_id = $secondary_cat->{"id"};
my @secondary_cat_stories = Bric::Biz::Asset::Business::Story->list({category_id=>$secondary_cat_id, element_id=>1, publish_status=>1, unexpired=>1, Order=>"cover_date", OrderDirection=>"DESC", Limit=>$return_limit});
foreach my $secondary_cat_story (@secondary_cat_stories){
my $current_id = $secondary_cat_story->get_id;
if($skip_story_id != $current_id){
if ($need_to_print_header) {
$m->print("<h4>more articles<br />ON RELATED TOPICS</h4>\n");
$need_to_print_header = 0;
}
++$count_returned;
my $secondary_cat_title = $secondary_cat_story->get_title;
my $secondary_cat_uri = $secondary_cat_story->get_uri;
my $secondary_cat_teaser = $secondary_cat_story->get_data('teaser');
$m->print("<p><a href=\"$secondary_cat_uri\" title=\"Read $secondary_cat_title\">$secondary_cat_title</a><br>$secondary_cat_teaser</p>\n");
if ($count_returned == $max_return) {last}
}
}
if ($count_returned == $max_return) {last}
}
</%perl>