Gossamer Forum
Home : Products : Links 2.0 : Customization :

Build Links Per Page, modify for different categories?

Quote Reply
Build Links Per Page, modify for different categories?
Would anyone have any idea on howto modify links to allow you to specify a different # of links per page, for different categories? Say I wanted to only display 10 links per page in the 'Blah' Category, but 20 links per page for all other categories?

Any Ideas?

Thanks,
--Jacob
Quote Reply
Re: Build Links Per Page, modify for different categories? In reply to
Hi there !!!

Where can I find the thread about the mod above ??? I tried the search, but nothing ...



Regards,

marcoBR

Quote Reply
Re: Build Links Per Page, modify for different categories? In reply to
This might not work, but try this (make backups):

In nph-build, find this:
Code:
# If we are spanning pages, we grab the first x number of links and build
# the main index page. We set $numlinks to the remaining links, and we remove
# the links from the list.
$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$next = $prev = $links = "";
if (($numlinks > $build_links_per_page) && $build_span_pages) {
Add a condition like:
Code:
if ($category =~ Blah) {$build_links_per_page = 10}
So it looks like:
Code:
# If we are spanning pages, we grab the first x number of links and build
# the main index page. We set $numlinks to the remaining links, and we remove
# the links from the list.
$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$next = $prev = $links = "";
if ($category =~ Blah) {$build_links_per_page = 10}
if (($numlinks > $build_links_per_page) && $build_span_pages) {
--Drew
Quote Reply
Re: Build Links Per Page, modify for different categories? In reply to
Because of the number of times the $build_links_per_page variable appears in nph-build.cgi, sub build_category_pages, I would put that conditional here so that it is used throughout the subroutine (just to be on the safe side):
Code:
# Go through each category and build the appropriate page.
CATEGORY: foreach $cat (sort keys Ętegory) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)
next CATEGORY if ($build_single and ($build_single ne $cat));
if ($category =~ Blah) { $build_links_per_page = 10; }
Actually, though, you really do not want to do it that way because, once you change $build_links_per_page, it will stay changed (it is a global variable). It would be best to do it like this:
Code:
# Go through each category and build the appropriate page.
my $links_per_page = "";
CATEGORY: foreach $cat (sort keys Ętegory) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)
next CATEGORY if ($build_single and ($build_single ne $cat));
if ($category =~ Blah) { $links_per_page = 10; }
else { $links_per_page = $build_links_per_page; }
Then change all other occurances of $build_links_per_page to $links_per_page in the rest of the subroutine.



I hope this helps.

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
Quote Reply
Re: Build Links Per Page, modify for different categories? In reply to
Thanks junko !!!


I had to make some changes in your code, but now it's working properly ...


So it looks like:

# If we are spanning pages, we grab the first x number of links and build
# the main index page. We set $numlinks to the remaining links, and we remove
# the links from the list.
$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$next = $prev = $links = "";
if ($category_name =~ /^Cat1/) {$build_links_per_page = 10}
elsif ($category_name =~ /^Cat2/) {$build_links_per_page = 5}
else {$build_links_per_page = 1}
if (($numlinks > $build_links_per_page) && $build_span_pages) {




Best regards,

marcoBR


Quote Reply
Re: Build Links Per Page, modify for different categories? In reply to
Thanks Bobsie,


I'll try to make this ...


Best regards,

marcoBR



Quote Reply
Re: Build Links Per Page, modify for different categories? In reply to
Hey, I never said it would work. Smile Thank you for correcting me, Bobsie. I'm still a novice at Perl but modding Links is a great learning experience. I had thought about a "my $links_per_page" thing but I didn't know exactly how to do it; now I do.

--Drew