Search

woo_pagination

Introduction ↑ Back to Top

Sometimes, the “next” and “previous” links on your blog page template or post archives just isn’t enough. Enter woo_pagination().

What is woo_pagination()? ↑ Back to Top

The woo_pagination() function creates easy to use paginated links for any WordPress loop (commonly used on blog post archive pages or the “Blog” page template).

Parameters ↑ Back to Top

Please note that all parameters are optional.

The $args array

  • base – The query argument on which to determine the pagination (for advanced users)
  • format – The format in which the query argument is formatted in it’s raw format (for advanced users)
  • total – The total amount of pages
  • current – The current page number
  • prev_next – Whether to include the previous and next links in the list or not.
  • prev_text – The previous page text. Works only if ‘prev_next’ argument is set to true.
  • next_text – The next page text. Works only if ‘prev_next’ argument is set to true.
  • show_all – If set to True, then it will show all of the pages instead of a short list of the pages near the current page. By default, the ‘show_all’ is set to false and controlled by the ‘end_size’ and ‘mid_size’ arguments.
  • end_size – How many numbers on either the start and the end list edges.
  • mid_size – How many numbers to either side of current page, but not including current page.
  • add_fragment – An array of query args to add using add_query_arg().
  • type – Controls format of the returned value. Possible values are:
    • ‘plain’ – A string with the links separated by a newline character.
    • ‘array’ – An array of the paginated link list to offer full control of display.
    • ‘list’ – Unordered HTML list.
  • before – The HTML to display before the paginated links.
  • after – The HTML to display after the paginated links.
  • echo – Whether or not to display the paginated links (alternative is to “return”).
  • use_search_permastruct- Whether or not to use the “pretty” permastruct on search results (if false, the default “raw” permastruct will be used).

The $query object

This allows for a custom query object to be specified for woo_pagination(). For advanced use only.

Examples ↑ Back to Top

Basic Usage

 
<?php if (have_posts()) : ?>  
<?php while (have_posts()) : the_post(); ?>
<div class="post"></div>
<?php endwhile; else: ?>
<div class="post">

Sorry, no posts matched your criteria.

 

</div>
<?php endif; ?> <?php woo_pagination(); ?>

Usage with custom arguments

In the example below, we’re using custom arguments to change the text of the “next” and “previous” links, as well as adding a title above the links.

 
<?php if (have_posts()) : ?>  
<?php while (have_posts()) : the_post(); ?>
<div class="post"></div>
<?php endwhile; else: ?>
<div class="post">

Sorry, no posts matched your criteria.

 

</div>
<?php endif; ?> <?php $args = array( 'prev_next' => true, 'prev_text' => __( '← Previous Entries', 'woothemes' ), 'next_text' => __( 'Next Entries →', 'woothemes' ), 'before' => '
<div class="pagination woo-pagination"><strong>' . __( 'Page through our blog posts', 'woothemes' ) . '</strong>
', 'after' => '</div>
' ); ?> <?php woo_pagination( $args ); ?>
Back to the top