AB Pagination documentation

AB Pagination adds a lot of flexibility and power to the default {exp:channel:entries} pagination functionality in ExpressionEngine.

Benefits

Some benefits over the standard EE pagination functionality:

  • Total control, you can skin it any way you want
  • Conditionals for has_previous, has_next etc. available
  • A lot of tags available for all kinds of different use-cases - can't solve a specific pagination case? Let us know!
  • The link to the first first page won't be postfixed with /P0 .. linking to /P0 basically creates duplicate content in Google, which is bad for SEO

Installation

  • Download and unzip ab_pagination.ee2_addon.zip
  • Copy the contents of system/expressionengine/third_party/ from the zip to system/expressionengine/third_party/ on your EE install
  • In the backend, navigate to Addons -> Extensions and then activate the "AB Pagination" extension.
  • Voilá! You can now use the tags described in this documentation inside the {exp:channel:entries} tags

Settings

AB Pagination has a single setting that lets you modify the tag prefix. By default it it set to "abp_". Changing it will modify all variables mentioned in this documentation (all conditionals, all variables). If you rename it from "abp_" to "myprefix_" for instance, {if abp_has_next} becomes {if myprefix_has_next} etc.

Tags

AB Pagination will make a bunch of additional conditionals and variables available inside the {paginate} tag pair that resides inside the {exp:channel:entries} tag.

Variables

On each page these variables are available:

  • {abp_pages} - this is a tag pair loop with the links and in many cases the only thing you'll use. If so, skip to the description below.
  • {abp_first_link} - the link to the first page
  • {abp_last_link} - the link to the last page
  • {abp_total_pages} - the total number of pages
  • {abp_entry_from} - the start entry number on the current page
  • {abp_entry_to} - the last entry number on the current page
  • {abp_total_entries} - the total number of entries
  • {abp_per_page} - the number of entries per page
  • {abp_current_page_num} - the current page number, starting on 0 (zero-based indexing)
  • {abp_current_page_num_liber} - the current page number, starting on 1
  • {abp_previous_page_num} - the previous page number (zero-based indexing)
  • {abp_previous_link} - the link to the previous page
  • {abp_next_page_num} - the page number of the next page (zero-based indexing)
  • {abp_next_link} - the link to the next page
  • {abp_query_string} - contain the query strings, if any (for this to work config param enable_query_strings in EE must be set to TRUE)

Conditionals

On each page these conditionals are available:

  • {if abp_has_previous} - does this page have a previous page? (if not, we're on the first)
  • {if abp_has_next} - does the current page have a next page? (if not, we're on the last)
  • {if abp_last_page_not_linked} - true if the last page is not linked in the {abp_pages} loop (yes, this can actually come handy in some cases)

The {ab_pages} tag pair

The {abp_pages} tag pair has its own set of variables and conditionals, and since this is the most important tag it gets its own section here in the documentation.

{abp_pages} Parameters

  • padding - optional, defaults to 3. If you do not want padding, set this to "no"
  • padding_left - optional, padding on the left side of the current page
  • padding_right - optional, padding on the right side of the current page
  • initial_size - optional, sets the initial number of pagelinks to show (by default the padding will decide this)
  • fixed_size - optional, sets a fixed number of pagelinks to show (this will override all other settings, ie. padding and initial_size .. so just use like this: {abp_pages fixed_size="5"} )

{abp_pages} Variables

  • {abp_link} - the link to the page
  • {abp_num} - the page number of the page (zero based)
  • {abp_previous_link} - the link to the previous page (empty if none)
  • {abp_previous_num} - the page number of the previous page (zero based)
  • {abp_next_link} - the link to the next page (empty if none)
  • {abp_next_num} - the page number of the next page (zero based)

{abp_pages} Conditionals

  • {if abp_is_current} - true if the current page in the loop is the current page
  • {if abp_is_last_page} - true if the current page in the loop is the last page
  • {if abp_is_first_page} - true if the current page in the loop is the first page
  • {if abp_has_previous} - true if the current page in the loop has a previous page
  • {if abp_has_next} - true if the current page in the loop has a next page

Examples

Flickr's pagination

Flickr has probably spent a good deal of man hours perfecting their pagination so we can only assume it's about as good as it gets(?). On the first page Flickr's pagination looks like this:

When paginating it looks like this:

So, this means we'd like to gray out the prev/next links if we do not have any more pages. Also, we want the initial number of pagination links to be 7, and we'd like to display 3 page links on each side of the current page. We'd also need the {abp_total_entries} tag to display the number of uploads. The code would look something like this:

{paginate}
{if abp_has_previous}
<a class="next" href="{abp_previous_link}">&larr; prev</a>
{if:else}
<span class="atStart">&larr; prev</span>
{/if}

{abp_pages padding="2" initial_size="5"}

{if abp_is_current}
<span class="this-page">{abp_num}</span>
{if:else}
<a href="{abp_link}">{abp_num}</a>
{/if}

{/abp_pages}

{if abp_has_next}
<a class="next" href="{abp_next_link}">next &rarr;</a>
{if:else}
<span class="atStart">next &rarr;</span>
{/if}

<div class="results">({abp_total_entries} uploads)</div>
{/paginate}

If we wanted we could even throw in the {abp_entry_from} to {abp_entry_to} variables in the mix to produce text like "Displaying X to XXX of XXX results":

Linking to the last page (if it's not already linked!)

We want the normal rules to apply, but in addition we want to link up the last page if it isn't already linked.

Here's where we need the {if abp_last_page_not_linked} conditional - we use it to add the three dots + the link to the last page in the numbered pagination links.

{paginate}

        {if abp_has_previous}
            
<class="next" href="{abp_previous_link}">&amp;larrprevious</a>
        
{if:else}
            
<span class="atStart">&amp;larrprevious</span>
        
{/if}

        {abp_pages padding
="6"}

            {if abp_is_current}
                
<span class="this-page">{abp_num}</span>
            
{if:else}
                
<a href="{abp_link}">{abp_num}</a>
            
{/if}

        {
/abp_pages}

        {if abp_has_next}
            
<class="next" href="{abp_next_link}">next &amp;rarr;</a>
        
{if:else}
            
<span class="atStart">next &amp;rarr;</span>
        
{/if}

        {if abp_last_page_not_linked}
            [
..<a href="{abp_last_link}">{abp_total_pages}</a>
        
{/if}

{
/paginate} 

Link'em all up

We want to display a link to each page.

This is an easy one with AB Pagination, just set padding="no" .. check out the code:

{paginate}
{abp_pages padding="no"}

{if abp_is_current}
<span class="this-page">{abp_num}</span>
{if:else}
<a href="{abp_link}">{abp_num}</a>
{/if}

{/abp_pages}
{/paginate}

Another example ..

Here's a pagination example we found over at thebestdesigns.com:

AB Pagination code to implement this:

{paginate}

<span class="count-span">Page {abp_current_page_num_liber} of {abp_total_pages}</span>

{abp_pages}

{if abp_is_current}
<span class="this-page">{abp_num}</span>
{if:else}
<a href="{abp_link}">{abp_num}</a>
{/if}

{/abp_pages}
<span class="padding">...</span>
<span class="last-page"> <a href="{abp_last_link}">Last&rarr;</a> </span>



{/paginate}

Example using Switchee

Switchee is a more efficient alternative to EE's standard {if}/{else} tags. Here's an example AB Paginaiton using Switchee, courtesy of Curtis Blackwell

{!--

This will only work if embedded in another switchee tag pair.
If it's not embedded, change the {switchee} tags to {exp:switchee}.

--}

{paginate}
{switchee variable="{abp_has_previous}"}
{case value="1"}
<a class="paginate_more" href="{abp_previous_link}">&larr;</a>
{/case}
{case value=""}
<span class="paginate_end">&larr;</span>
{/case}
{/switchee}

{abp_pages padding="5"}
{switchee variable="{abp_is_current}"}
{case value="1"}
<span class="paginate_current">{abp_num}</span>
{/case}
{case value=""}
<a href="{abp_link}">{abp_num}</a>
{/case}
{/switchee}
{/abp_pages}

{switchee variable="{abp_has_next}"}
{case value="1"}
<a class="paginate_more" href="{abp_next_link}">&rarr;</a>
{/case}
{case value=""}
<span class="paginate_end">&rarr;</span>
{/case}
{/switchee}
{/paginate}

Compatibility with other 3rd party addons

So far AB Pagination has been tested and found working with:

  • Structure (courtesy of Wouter Vervloet)
  • SolSpace Tag
  • Dynamo
  • Freebie
  • Switchee (courtesy of Curtis Blackwell)

Using AB Pagination with {exp:query}?

That won't work since {exp:query} will overwrite whatever pagination produced by the {exp:channel:entries} tag. Not to worry though, we have a solution for this.

Download our AB Entry IDs addon and use that instead of {exp:query}. Check out the docs for an example on how to use it with AB Pagination.