How do I show First and Last links like expression engine natively does?

  • Problem
  • Updated 4 years ago
The pagination at the bottom of the expressionengine forums (http://expressionengine.com/forums/vi...) is what I would like to replicate, but with a padding of 3 links on each side of the current page link instead of 2.

The default EE pagination doesn't show the First link until the left most link is > 1, and it doesn't show the Last link until the right most link is < the total number of pages.

So I tried to incorporate that logic using the following:
http://pastebin.com/X5pW68BD

But that didn't work. Being on the first page gave these values:
abp_entry_from = 1, abp_entry_to = 1, abp_current_page_num = 0
And being on page 2 gave these values:
abp_entry_from = 2, abp_entry_to = 2, abp_current_page_num = 1
So I couldn't use abp_entry_from and abp_entry_to as I'd hoped.

What should I change in code to get this to work?
Photo of EricE

Eric

  • 10 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Bjørn Børresen

Bjørn Børresen, Company Admin

  • 1159 Posts
  • 39 Reply Likes
Hi Eric,

you could probably use the {abp_current_page_num} instead and check that this is > 0 before displaying the First link.

And for the last link that seems to always be shown so unless you're on the last page so display it if {abp_current_page_num} < {abp_total_pages}.
Photo of EricE

Eric

  • 10 Posts
  • 0 Reply Likes
Thanks for the reply!

I tried both suggestions but they aren't showing quite the way I wanted.

Let's say there are 10 pages to paginate. With a padding of 3, I want the First link to only show from pages 5 to 10 and the Last link to show from pages 1 to 6.

Here's an example of what you would see on pagination page 4:

(Prev) (1) (2) (3) [ 4 ] (5) (6) (7) (Next) (Last)

And on page 5:

(First) (Prev) (2) (3) (4) [ 5 ] (6) (7) (8) (Next) (Last)

Page 6:

(First) (Prev) (3) (4) (5) [ 6 ] (7) (8) (9) (Next) (Last)

Page 7:

(First) (Prev) (4) (5) (6) [ 7 ] (8) (9) (10) (Next)

Basically, I only want to show the First link when you can no longer see the first page within the padding and the Last link when you can no longer see last page in the padding.
Photo of Bjørn Børresen

Bjørn Børresen, Company Admin

  • 1159 Posts
  • 39 Reply Likes
Hmm,

so are you saying you can't use the current page num variable to check for this? Why/what happens?

http://www.addonbakery.com/docs/pagin...
Photo of EricE

Eric

  • 10 Posts
  • 0 Reply Likes
Nevermind the last post, I got it to work.

To show the First link, I used

{if abp_current_page_num > 3}« First{/if}

To show the Last link, I used the MX Calculator plugin and

{if abp_current_page_num < {exp:mx_calc expression="{abp_total_pages}-4"}}Last »{/if}

where 3 is the padding parameter and 4 is padding + 1