I have now written a second version of the mod for those who like to use the original way of listing the cool page - with categories.
You can now retain the category headings before the cool links in each category, and the pages span correctly with the exact
number of links per page.
You only have to modify sub build_cool_page in nph-build.cgi - so it's very simple.
Just replace your existing sub build_cool_page with the following: -
# --------------------------------------------------------
# Creates spanned "What's Cool" pages.
local ($total, $hits, $percent, $link_results, $title_linked, $title, $next, $prev);
my (%link_output, $category_clean, $url, $page_num, $prev_page, $next_page, $numlinks);
if ($build_cool_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
$total = 0;
$numlinks = 0;<p> CATEGORY: foreach $category (sort keys %cool_links) {
LINK: for ($i = 0; $i < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
}
}<p> $numlinks = $total;<p> $title_linked = &build_linked_title ("Cool");
open (COOL, ">$build_cool_path/$build_index") or cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!");
print "\tCool Links: $total\n";
($db_popular_cutoff < 1) ?
($percent = $db_popular_cutoff * 100 . "%") :
($percent = $db_popular_cutoff);
close COOL;
$url = $build_cool_url;<p> $next = $prev = $link_results = "";
if (($numlinks > $build_links_per_page) && $build_span_pages) {
$total_pages=(int($numlinks/$build_links_per_page));
if ($total_pages < $numlinks/$build_links_per_page) {$total_pages++}
$next .= "<b>1</b>"; # new added
for $j(2..($total_pages)){
$next .= qq~ <a href="more$j$build_extension">$j</a>~;
} # end of for #added
$page_num = 2;
$next .= qq~ <a href="more$page_num$build_extension">[Next >>]</a>~;
$p = 1;
$t = 0;
$i = 0;
$r = 0; <p> foreach $category (sort keys %cool_links) {
$category_clean = &build_clean ($category);
if ($i < $build_links_per_page) {
LINK: for ($q = 0; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) {
if ($i < $build_links_per_page) {
%tmp = &array_to_hash ($q, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
$i++;
}
else {
$r--;
$t = $q;
last; }
}
$link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
$r++;
}
}
$p++;
$numlinks = $numlinks - $i;
}<p># Otherwise we either only have less then x number of links, or we are not
# splitting pages, so let's just build them all.<p> else {
foreach $category (sort keys %cool_links) {
$category_clean = &build_clean ($category);
LINK: for ($q = 0; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) {
%tmp = &array_to_hash ($q, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
}<p> $link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
}
}<p># Create the main page.
open (COOL, ">$build_cool_path/$build_index") or &cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!");
print COOL &site_html_cool(@cool_links);
close COOL;<p># Then we go through the list of links and build on the remaining pages.
while ($next && $build_span_pages) {
if ($numlinks > $build_links_per_page) {
$prev=$next=$next_page=$prev_page="";
$next_page = $page_num+1;
$prev_page = $page_num-1;
if ($page_num == 2){
$prev .= qq~ <a href="$url">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url"> 1</a> ~;}
else {$prev .= qq~ <a href="more$prev_page$build_extension">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a href="more$k$build_extension">$k</a>~;}}
$next .= qq~ <b>$page_num</b> ~;
for $m($next_page..$total_pages){$next .= qq~ <a href="more$m$build_extension">$m</a>~;}
$next .= qq~ <a href="more$next_page$build_extension">[Next >>]</a>~;
} # end of if
else {
if ($page_num == $total_pages) {
$prev = $next = $next_page = $prev_page= "";
$prev_page=$total_pages-1;
if ($page_num == 2){
$prev .= qq~ <a href="$url">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url"> 1</a> ~;}
else {$prev .= qq~ <a href="more$prev_page$build_extension">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a href="more$k$build_extension">$k</a>~;}
} # end of else
$prev .= qq~ <b>$page_num</b> ~;
} # end of if
} # end of else
$link_results = "";
$i = 0;
$s = 1;
foreach $category (sort keys %cool_links) {
if (($s > $r) && ($i < $build_links_per_page)) {
$category_clean = &build_clean ($category);
$link_output{$category} = "";
LINK: for ($q = $t; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) {
if ($i < $build_links_per_page) {
%tmp = &array_to_hash ($q, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
$i++;
$t = 0;<p> }
else {
$r--;
$t = $q;
last; }<p>
}<p>
$link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
$r++;
}
$s++;
}
$title_linked = &build_linked_title ("$cat/Page_$page_num/");
$title = &build_unlinked_title ("$cat/Page_$page_num/");
$use_html ?
print qq|\tSubpage : <A HREF="|, $url, qq|more$page_num$build_extension" TARGET="_blank">$build_cool_path/more$page_num$build_extension</A>\n| :
print qq|\tSubpage : $build_cool_path/more$page_num$build_extension\n|;
open (COOL, ">$build_cool_path/more$page_num$build_extension") or &cgierr ("unable to open what's cool page: $build_cool_path/index$page_num$build_extension. Reason: $!");
print COOL &site_html_cool(@cool_links);
close COOL;
$p++;
$numlinks = $numlinks - $i;
if ($page_num == $total_pages) { last; }
else { $page_num++; }
}
print "\n";
}
Then add the "prev => $prev" and "next => $next" lines to site_html_templates.pl under sub site_html_cool like this: -
# --------------------------------------------------------
# This routine will build a what's cool page. <p> return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
prev => $prev,
next => $next,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}
and finally add the tags to the cool.html template above and below the link results like this: -
<%if prev%>
<%prev%>
<%endif%>
<%if next%>
<%next%>
<%endif%>
</center>
<%link_results%>
<center>
<%if prev%>
<%prev%>
<%endif%>
<%if next%>
<%next%>
<%endif%>
</center>
Warwick.
------------------
HumorLinks Comedy Search, Humor DVD and Video Store
http://www.humorlinks.com
humorlinks@humorlinks.com
You can now retain the category headings before the cool links in each category, and the pages span correctly with the exact
number of links per page.
You only have to modify sub build_cool_page in nph-build.cgi - so it's very simple.
Just replace your existing sub build_cool_page with the following: -
Code:
sub build_cool_page { # --------------------------------------------------------
# Creates spanned "What's Cool" pages.
local ($total, $hits, $percent, $link_results, $title_linked, $title, $next, $prev);
my (%link_output, $category_clean, $url, $page_num, $prev_page, $next_page, $numlinks);
if ($build_cool_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}
$total = 0;
$numlinks = 0;<p> CATEGORY: foreach $category (sort keys %cool_links) {
LINK: for ($i = 0; $i < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
}
}<p> $numlinks = $total;<p> $title_linked = &build_linked_title ("Cool");
open (COOL, ">$build_cool_path/$build_index") or cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!");
print "\tCool Links: $total\n";
($db_popular_cutoff < 1) ?
($percent = $db_popular_cutoff * 100 . "%") :
($percent = $db_popular_cutoff);
close COOL;
$url = $build_cool_url;<p> $next = $prev = $link_results = "";
if (($numlinks > $build_links_per_page) && $build_span_pages) {
$total_pages=(int($numlinks/$build_links_per_page));
if ($total_pages < $numlinks/$build_links_per_page) {$total_pages++}
$next .= "<b>1</b>"; # new added
for $j(2..($total_pages)){
$next .= qq~ <a href="more$j$build_extension">$j</a>~;
} # end of for #added
$page_num = 2;
$next .= qq~ <a href="more$page_num$build_extension">[Next >>]</a>~;
$p = 1;
$t = 0;
$i = 0;
$r = 0; <p> foreach $category (sort keys %cool_links) {
$category_clean = &build_clean ($category);
if ($i < $build_links_per_page) {
LINK: for ($q = 0; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) {
if ($i < $build_links_per_page) {
%tmp = &array_to_hash ($q, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
$i++;
}
else {
$r--;
$t = $q;
last; }
}
$link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
$r++;
}
}
$p++;
$numlinks = $numlinks - $i;
}<p># Otherwise we either only have less then x number of links, or we are not
# splitting pages, so let's just build them all.<p> else {
foreach $category (sort keys %cool_links) {
$category_clean = &build_clean ($category);
LINK: for ($q = 0; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) {
%tmp = &array_to_hash ($q, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
}<p> $link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
}
}<p># Create the main page.
open (COOL, ">$build_cool_path/$build_index") or &cgierr ("unable to open what's cool page: $build_cool_path/$build_index. Reason: $!");
print COOL &site_html_cool(@cool_links);
close COOL;<p># Then we go through the list of links and build on the remaining pages.
while ($next && $build_span_pages) {
if ($numlinks > $build_links_per_page) {
$prev=$next=$next_page=$prev_page="";
$next_page = $page_num+1;
$prev_page = $page_num-1;
if ($page_num == 2){
$prev .= qq~ <a href="$url">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url"> 1</a> ~;}
else {$prev .= qq~ <a href="more$prev_page$build_extension">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a href="more$k$build_extension">$k</a>~;}}
$next .= qq~ <b>$page_num</b> ~;
for $m($next_page..$total_pages){$next .= qq~ <a href="more$m$build_extension">$m</a>~;}
$next .= qq~ <a href="more$next_page$build_extension">[Next >>]</a>~;
} # end of if
else {
if ($page_num == $total_pages) {
$prev = $next = $next_page = $prev_page= "";
$prev_page=$total_pages-1;
if ($page_num == 2){
$prev .= qq~ <a href="$url">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url"> 1</a> ~;}
else {$prev .= qq~ <a href="more$prev_page$build_extension">[<< Prev]</a> ~;
$prev .= qq~ <a href="$url">1</a> ~;
for $k(2..$prev_page){$prev .= qq~ <a href="more$k$build_extension">$k</a>~;}
} # end of else
$prev .= qq~ <b>$page_num</b> ~;
} # end of if
} # end of else
$link_results = "";
$i = 0;
$s = 1;
foreach $category (sort keys %cool_links) {
if (($s > $r) && ($i < $build_links_per_page)) {
$category_clean = &build_clean ($category);
$link_output{$category} = "";
LINK: for ($q = $t; $q < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $q++) {
if ($i < $build_links_per_page) {
%tmp = &array_to_hash ($q, @{$cool_links{$category}});
$link_output{$category} .= &site_html_link (%tmp) . "\n";
$i++;
$t = 0;<p> }
else {
$r--;
$t = $q;
last; }<p>
}<p>
$link_results .= qq|<P><A HREF="$build_root_url/$category/$build_index">$category_clean</A>\n|;
$link_results .= $link_output{$category};
$r++;
}
$s++;
}
$title_linked = &build_linked_title ("$cat/Page_$page_num/");
$title = &build_unlinked_title ("$cat/Page_$page_num/");
$use_html ?
print qq|\tSubpage : <A HREF="|, $url, qq|more$page_num$build_extension" TARGET="_blank">$build_cool_path/more$page_num$build_extension</A>\n| :
print qq|\tSubpage : $build_cool_path/more$page_num$build_extension\n|;
open (COOL, ">$build_cool_path/more$page_num$build_extension") or &cgierr ("unable to open what's cool page: $build_cool_path/index$page_num$build_extension. Reason: $!");
print COOL &site_html_cool(@cool_links);
close COOL;
$p++;
$numlinks = $numlinks - $i;
if ($page_num == $total_pages) { last; }
else { $page_num++; }
}
print "\n";
}
Then add the "prev => $prev" and "next => $next" lines to site_html_templates.pl under sub site_html_cool like this: -
Code:
sub site_html_cool { # --------------------------------------------------------
# This routine will build a what's cool page. <p> return &load_template ('cool.html', {
total => $total,
grand_total => $grand_total,
percent => $percent,
prev => $prev,
next => $next,
link_results => $link_results,
title_linked => $title_linked,
%globals
} );
}
and finally add the tags to the cool.html template above and below the link results like this: -
Code:
<center> <%if prev%>
<%prev%>
<%endif%>
<%if next%>
<%next%>
<%endif%>
</center>
<%link_results%>
<center>
<%if prev%>
<%prev%>
<%endif%>
<%if next%>
<%next%>
<%endif%>
</center>
Warwick.
------------------
HumorLinks Comedy Search, Humor DVD and Video Store
http://www.humorlinks.com
humorlinks@humorlinks.com