Gossamer Forum
Quote Reply
span pages
Hi there,

we are using the following global span pages:

sub {
my $top_category=shift;
my $tags=shift;
my $nh = $IN->param('nh')||1;
($nh =~ /\d+/) || ($nh=1);
my $page=$IN->param('p');
my $maxhits = $tags->{maxhits}||10;
($maxhits =~ /\d+/) || ($maxhits=10);
my $category = $DB->table('Category')->get($top_category);
my $db=$DB->table('Links','CatLinks','Category');
my $cond = GT::SQL::Condition->new('isNew', '=', 'Yes', 'Full_Name', 'like', $category->{Full_Name} . '%');
my $numhits = $db->count ( $cond );
my ($next_url, $max_page, $next_hit, $prev_hit, $left, $right, $upper, $lower, $first, $url, $last, $i);
return unless ($numhits > $maxhits);
$next_hit = $nh + 1;
$prev_hit = $nh - 1;
$max_page = int ($numhits / $maxhits) + (($numhits % $maxhits) ? 1 : 0);
$left = $nh;
$right = int($numhits/$maxhits) - $nh;
($left > 7) ? ($lower = $left - 7) : ($lower = 1);
($right > 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);
(7 - $nh >= 0) and ($upper = $upper + (8 - $nh));
($nh > ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));
$url = "";
($nh > 1) and ($url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&t=english">[<<]</a> ~);
($nh > 1) and ($url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$prev_hit&t=english">[<]</a> ~);
for ($i = 1; $i <= int($numhits/$maxhits) + 1; $i++) {
if ($i < $lower) { $url .= " ... "; $i = ($lower-1); next; }
if ($i > $upper)
{ $url .= " ... "; last; }
($i == $nh) ? ($url .= qq~$i ~) : ($url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$i&t=english">$i</a> ~);
if ($i * $maxhits == $numhits) { $nh == $i and $next_hit = $i; last; }
}
$url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$next_hit&t=english">[>]</a> ~ unless ($next_hit == $nh or ($nh * $maxhits > $numhits));
$url .= qq~<a href="$CFG->{db_cgi_url}/page.cgi?p=$page&nh=$max_page&t=english">[>>]</a> ~ unless ($next_hit == $nh or ($nh * $maxhits > $numhits));
return {span=>$url,total=>$numhits};
}

The global looks for links that have a certain category, specified in <%global('1')%>. We would like to modify the global that way that we can use it for any link, not just for new one.


Cheers

Stuart
Quote Reply
Re: [vacationrentals] span pages In reply to
Hi Stuart,

Just change

my $cond = GT::SQL::Condition->new('isNew', '=', 'Yes', 'Full_Name', 'like', $category->{Full_Name} . '%');

to

my $cond = GT::SQL::Condition->new('Full_Name', 'like', $category->{Full_Name} . '%');

Laura.
The UK High Street
Quote Reply
Re: [vacationrentals] span pages In reply to
Just a note to anyone using span pages, since I put these globals on the forum, I realised that there is a toolbar function that you can use already built into Links.

So you could write this global more simply as (I think):

sub {
my $top_category=shift;
my $tags=shift;
my $nh = $IN->param('nh')||1;
($nh =~ /\d+/) || ($nh=1);
my $page=$IN->param('p');
my $maxhits = $tags->{maxhits}||10;
($maxhits =~ /\d+/) || ($maxhits=10);
my $category = $DB->table('Category')->get($top_category);
my $db=$DB->table('Links','CatLinks','Category');
my $cond = GT::SQL::Condition->new('isNew', '=', 'Yes', 'Full_Name', 'like', $category->{Full_Name} . '%');
my $numhits = $db->count ( $cond );
my $url = $CFG->{db_cgi_url} . "/" . $IN->url( query_string => 1, absolute => 0 );
my $toolbar = $DB->html($db, $IN)->toolbar( $nh, $maxhits, $numhits, $url);
return {span=>$toolbar,total=>$numhits};
}
Quote Reply
Re: [afinlr] span pages In reply to
Don't you use [code] tags any more? Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] span pages In reply to
Wink No - I'm not a fan after once writing a very long post and half of it disappeared when it was posted. I'm sure that was a bug that's long since been removed but I've got out of the habit now. Does it really annoy you?
Quote Reply
Re: [afinlr] span pages In reply to
LOL...I know the feeling. It doesn't bother me... I was just wondering if there was a reason behind it :p

I normally just type the message in the basic editor, and manually put the tags around stuff that should be surrounded as code :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [afinlr] span pages In reply to
Cheers for that!