Title: Pagination outside the Loop
Last modified: August 21, 2016

---

# Pagination outside the Loop

 *  Resolved [jtrollia](https://wordpress.org/support/users/malivuk/)
 * (@malivuk)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/pagination-outside-the-loop/)
 * Hi everyone,
 * I read articles and codex about pagination but it usually seems to work in the
   Loop.
    For some style reasons, I need to create a pagination block outside the
   main loop but for the main loop… Implying existence of some query_posts loops
   between the Loop and the pagination.
 * I tried something like that :
 *     ```
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   
       query_posts(array(
       	'post_type'      => 'post',
       	'paged'          => $paged,
       	'posts_per_page' => 10
               'cat'            => '1,2,3'
       ));
       ```
   
 * But it returns nothing.
    Thanks for tips !
 * _[ Please do not bump, that’s [not permitted here](http://codex.wordpress.org/Forum_Welcome#No_Bumping).]_

Viewing 1 replies (of 1 total)

 *  Thread Starter [jtrollia](https://wordpress.org/support/users/malivuk/)
 * (@malivuk)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/pagination-outside-the-loop/#post-3978183)
 * //Not a bump
 * How I solved my problem :
 * I put the following code in functions.php :
 *     ```
       if ( ! function_exists( 'pagination' ) ) :
       	function pagination() {
                  global $wp_query;
                  $big = 999999999;
                  global $pagination;
                                       $pagination = paginate_links( array(
                                                                           'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                                                                           'format' => '?paged=%#%',
                                                                           'current' => max( 1, get_query_var('paged') ),
                                                                           'total' => $wp_query->max_num_pages
                                                                           ) );
                                    }
       endif;
       ```
   
 * Then, I call _pagination();_ right after the Loop. I display the result at the
   bottom of my page with :
 *     ```
       <?php
           if ($pagination=='') {
           echo "Tous les r&eacutesultats sont affich&eacutes.";
           } else {
           echo $pagination;
           }
           ?>
       ```
   
 * If it helps somebody else.

Viewing 1 replies (of 1 total)

The topic ‘Pagination outside the Loop’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [jtrollia](https://wordpress.org/support/users/malivuk/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/pagination-outside-the-loop/#post-3978183)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
