Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

span_pages on the login_success.html

Quote Reply
span_pages on the login_success.html
Hello,

I use the Global following on the login_success.html page.

<%display_users_links%>

sub {
my $output;
my $sth = $DB->table('Links')->select( { LinkOwner => $USER->{Username} } );
while (my $rec = $sth->fetchrow_hashref ) {

$output .= Links::SiteHTML::display('link4', $rec );

}
return $output;
}

-------------------

But, I have a problem.

I have two users who have 40 links.

I will like to post less links on the page.
And to have a bar of navigation (1. 2. 3. > >) etc.

I sought on the forum a solution.
I found this Global.

But, it is difficult for me to work with !

You can say to me if this total can bring an answer?

------------------

<%span_pages%>


sub {
# ---------------------------------------------------------------
# Display/calculate a "next hits" toolbar.
#

my ($nh) = @_;
my $maxhits = 10; #links per page
my $numhits = 100; #total number - use a table count to get a precise number or just add your max here
my ($next_url, $max_page, $next_hit, $prev_hit, $left, $right, $upper, $lower, $first, $url, $last, $i);

# Return if there shouldn't be a speedbar.
return unless ($numhits > $maxhits);

$next_hit = $nh + 1;
$prev_hit = $nh - 1;
$max_page = int ($numhits / $maxhits) + (($numhits % $maxhits) ? 1 : 0);

# First, set how many pages we have on the left and the right.
$left = $nh;
$right = int($numhits/$maxhits) - $nh;

# Then work out what page number we can go above and below.
($left > 7) ? ($lower = $left - 7) : ($lower = 1);
($right > 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);

# Finally, adjust those page numbers if we are near an endpoint.
(7 - $nh >= 0) and ($upper = $upper + (8 - $nh));
($nh > ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));
$url = "";
# Then let's go through the pages and build the HTML.
($nh > 1) and ($url .= qq~<a href="page1.html">[&lt;&lt;]</a> ~);
($nh > 1) and ($url .= qq~<a href="page$prev_hit.html">[&lt;]</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="page$i.html">$i</a> ~);
if ($i * $maxhits == $numhits) { $nh == $i and $next_hit = $i; last; }
}
$url .= qq~<a href="page$next_hit.html">[&gt;]</a> ~ unless ($next_hit == $nh or ($nh * $maxhits > $numhits));
$url .= qq~<a href="page$max_page.html">[&gt;&gt;]</a> ~ unless ($next_hit == $nh or ($nh * $maxhits > $numhits));
return $url;
}

-----------------------------------
http://www.gossamer-threads.com/...i?post=237934#237934


Thank you for your assistance.

Mick
Quote Reply
Re: [mick31] span_pages on the login_success.html In reply to
Mick, this is a better thread:

http://www.gossamer-threads.com/...i?post=249348#249348