WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination outside the Loop (2 posts)

  1. Malivuk
    Member
    Posted 1 year ago #

    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. ]

  2. Malivuk
    Member
    Posted 1 year ago #

    //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.

Topic Closed

This topic has been closed to new replies.

About this Topic