Gossamer Forum
Home : Products : Gossamer Links : Discussions :

current link number

(Page 1 of 2)
> >
Quote Reply
current link number
I am trying to add numbers to display the links being viewed. For example:

1 - 25 of 450 Links,
26 - 50 of 450 Links,
etc...

Here's what I have so far:

Code:
<%if nh >= 2%> NEED HELP HERE - <%nh * 25%><%else%>1 - 25<%endif%> of <%link_hits%>

I can't figure out the syntax for creating the first number. It doesn't seem to be able to do multiple mathmatical functions. For example:

Code:
<%nh * 25 - 24%>

Does anyone know of a (better) way to do this?

Sean
Quote Reply
Re: [SeanP] current link number In reply to
It may be easier to create a global instead of attempting this in the template, but I'm not sure if you can determine the page the user is viewing (nh variable) from a global. Has anyone ever created something that does this?

Sean
Quote Reply
Re: [SeanP] current link number In reply to
Alex, can you add any insight to this?

Sean
Quote Reply
Re: [SeanP] current link number In reply to
Hi Sean -

Try this global:

span_firstnumber =>
Code:
sub {
my $tags = shift; # available tags
my $firstnumber;
if($tags->{nh}) {
$firstnumber = ($tags->{nh} * 25) - 24;
}
return $firstnumber;
}


If <%nh%> is a valid tag on the page you are working with, I believe this global should pick it up and process it properly.

--
Matt G
Quote Reply
Re: [SeanP] current link number In reply to
Here's something you can add to your globals:
Code:
'sub {
my $vars = shift;
my $mh = $Links::CFG->{search_maxhits};
my $nh = $vars->{nh} || 1;
my $hits = $vars->{link_hits};
return ((($nh - 1) * $mh) + 1) . " - " . ($nh * $mh) . " of $hits Links";
}'
That being used for displaying the link result range for searches.


Adrian
Quote Reply
Re: [brewt] current link number In reply to
Except with that you end up with things like:

16 - 20 of 16 Links

Try this instead:

Code:
sub {

my $tags = shift;
my $total = $tags->{link_hits};
my $high = $Links::CFG->{search_maxhits};
my $low = 1;
my $page = $tags->{nh} || 1;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

return "Viewing $low to $top of $total";

}


Quote Reply
Re: [PaulW] current link number In reply to
Thanks for everyone's help. That seems to work great.

Sean
Quote Reply
Re: [Paul] current link number In reply to
hey paul,

i took this code:


sub {

my $tags = shift;
my $total = $tags->{link_hits};
my $high = $Links::CFG->{search_maxhits};
my $low = 1;
my $page = $tags->{nh} || 1;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

return "Viewing $low to $top of $total";

}


and added it to my list of globals and called it display_total. then, i added the tag <%display_total%> to my category.html page under the link section. but, the only thing that is being displayed is:

"Viewing 1 to of"

i have the links set to 10 a page. and i would like it to display this:

Total: 16 Displaying: 1 - 10

could you explain how i i would go about setting that up?

thank you,

eddie


Quote Reply
Re: [eddie123] current link number In reply to
I'm having the same problem.

Only "Viewing 1 to of" shows up.

Can anyone help?

Regards,

Blake
Quote Reply
Re: [blakeb] current link number In reply to
This global was designed to be used on the search_results.html template. If you are going to use it on the category.html template, the "nh" tag that holds the current page number is not going to be available on that template. That's why it isn't working. In looking at the tags available on the category.html template, I don't see a tag that only displays the current page number. One of the only tags I see that has the page number in it is the "title" tag. So, unless you've changed the default way the "title" tag is displayed, we can extract the current page number from it to use in the calculations of this global. Try the following:

Code:
sub {

my $tags = shift;
my $total = $tags->{total};
my $high = $Links::CFG->{build_links_per_page};
my $low = 1;
my $name = $tags->{Full_Name};
$name =~ s/\//\: /g;
$name =~ s/$name/$name: Page /g;
my $page = $tags->{title};
$page =~ s/$name//g;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}else{
$page = 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

return "$low - $top of $total";

}

Like I said, this will only work if you haven't changed the way the "title" tag is displayed. The "title" tag is the category path and page number displayed at the top of the template which, for example, looks like:

Computers: Algorithms: Page 2

This is a pretty cheesy way of getting the page number, but it works. Someone else may have a better idea, but this is what I came up with quickly.

BTW: I only tested this in dynamic mode. I'm not sure about static mode.

Sean

Last edited by:

SeanP: Feb 28, 2003, 11:04 PM
Quote Reply
Re: [SeanP] current link number In reply to
Hi,

How can you insert , in the numbers?

Ex.
instead of 'viewing 1000 to 1010 of 2000' I need:

'viewing 1,000 to 1,010 of 2,000'


Cheers
Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] current link number In reply to
Try:

Code:
sub {

my $tags = shift;
my $total = $tags->{total};
my $high = $Links::CFG->{build_links_per_page};
my $low = 1;
my $name = $tags->{Full_Name};
$name =~ s/\//\: /g;
$name =~ s/$name/$name: Page /g;
my $page = $tags->{title};
$page =~ s/$name//g;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}else{
$page = 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

$low =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$top =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$total =~ s/^([-+]?\d+)(\d{3})/$1,$2/;

return "$low - $top of $total";

}

Sean
Quote Reply
Re: [SeanP] current link number In reply to
Hi Sean,

Thanks - but it it not working - I tried something like that but get '1 - of '

Any ideas?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] current link number In reply to
I'm using it on my site, and it works. Are you using this global on the category.html template? If so, does the header or "title" tag being displayed look like that format:

Home : Computers : Algorithms : Page 2

Sean
Quote Reply
Re: [SeanP] current link number In reply to
Nope - I am using it on search results....(and it works - just not with comma)

This is the code I use:

Code:
sub {

my $tags = shift;
my $total = $tags->{link_hits};
my $high = $Links::CFG->{search_maxhits};
my $low = 1;
my $page = $tags->{nh} || 1;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);
return "Viewing $low to $top of $total";

}
Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] current link number In reply to
Oh, the one I gave you was for the category.html template. For search_results.html, do:

Code:
sub {

my $tags = shift;
my $total = $tags->{link_hits};
my $high = $IN->param('mh');
my $low = 1;
my $page = $tags->{nh} || 1;

if ($high > 0) {
$high = $IN->param('mh');
}else{
$high = $Links::CFG->{search_maxhits};
}

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

$low =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$top =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$total =~ s/^([-+]?\d+)(\d{3})/$1,$2/;

return "$low - $top of $total";

}

Also, for the category matches on the search_results.html template, you can create another new global with this code and just replace:

Code:
my $total = $tags->{link_hits};
with
Code:
my $total = $tags->{cat_hits};

I hope that works for you. Wink
Sean

Last edited by:

SeanP: Mar 7, 2003, 11:56 PM
Quote Reply
Re: [SeanP] current link number In reply to
could someone update this?
it stopped working
after I upgraded links sql to the latest version

Thanks


Code
sub {

my $tags = shift;
my $total = $tags->{total};
my $high = $Links::CFG->{build_links_per_page};
my $low = 1;
my $name = $tags->{Full_Name};
$name =~ s/\//\: /g;
$name =~ s/$name/$name: Page /g;
my $page = $tags->{title};
$page =~ s/$name//g;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
}else{
$page = 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

$low =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$top =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$total =~ s/^([-+]?\d+)(\d{3})/$1,$2/;

return "$low - $top of $total";

}[/code]

Quote Reply
Re: [incik] current link number In reply to
Hi,

This any good?

Code:
sub {

my $tags = shift;
my $total = $tags->{total};

my $high = $CFG->{build_links_per_page};
my $low = 1;

my $name = $tags->{Full_Name};
$name =~ s/\//\: /g;
$name =~ s/$name/$name: Page /g;

my $page = $tags->{title};
$page =~ s/$name//g;

if ($page > 1) {
$low = (($page - 1) * $high) + 1;
} else {
$page = 1;
}

my $top = ($high + $low > $total) ? $total : (($high + $low) - 1);

$low =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$top =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
$total =~ s/^([-+]?\d+)(\d{3})/$1,$2/;

return "$low - $top of $total";

}

Main changes are the $Links::CFG->{build_links_per_page}; format - I'm not familiar with that (it may be supported).

I've changed it to;

$CFG->{build_links_per_page};

..for you, as I know thats a valid value =)

Hope that helps.

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] current link number In reply to
Andy,

it still doesnt work
if theres 34 links in a category I get a crazy number like this
1414337,791 - 34 of 34

is there anything else you think it might be?
Quote Reply
Re: [incik] current link number In reply to
Try changing

my $total = $tags->{total};

to

my $total = (ref $tags->{total} ? ${$tags->{total}} : $tags->{total});

Edit: Taking another look this shouldn't be affecting the low number - I think it is more likely to be a change to the 'title' tag.

Last edited by:

afinlr: Jan 17, 2006, 4:40 PM
Quote Reply
Re: [afinlr] current link number In reply to
Thanks for trying but still no luck
Quote Reply
Re: [incik] current link number In reply to
You just missed my edit. Tongue Has the title tag changed?
Quote Reply
Re: [afinlr] current link number In reply to
Edit: It's late here! I'll try again. Having read the rest of the thread now, I see that this was written because there was no nh tag on the category pages - however, I think there is now. So you should be able to replace all this code:

Code:
my $name = $tags->{Full_Name};
$name =~ s/\//\: /g;
$name =~ s/$name/$name: Page /g;

my $page = $tags->{title};
$page =~ s/$name//g;


and use this instead

Code:
my $page = (ref $tags->{nh} ? ${$tags->{nh}} : $tags->{nh}) || 1;



Last edited by:

afinlr: Jan 17, 2006, 4:53 PM
Quote Reply
Re: [afinlr] current link number In reply to
Hi,

It partially works

it displays 1 - 10 of 34
but when you go to the next spanned page it should say 11 - 21 of 34
but it stays the same on all the spanned pages

Thanks for trying
Quote Reply
Re: [incik] current link number In reply to
OK - having investigated this a bit more ... I think I have nh on my category pages due to one of my plugins. However it is available on the as <%paging.current_page%>. So you can use

my $page = $tags->{paging}->{current_page};

This time I've tested it!
> >