wordpress Static Page pagination

Im Using a post query in wordpress BUT the Pagination is not working, i don’t know whats the problem BUT here is my code and i guess it’s correct and no problem with it

it shows that there is pages BUT when i Click on Next Page it refresh the page and don’t show any new results just the same page.

Im Using it on Static page to be The Home page of my theme

<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$post_query = query_posts(array(
    'post_type'      => 'cover', // You can add a custom post type if you like
    'paged'          => $paged,
    'posts_per_page' => 1
));

?>

<?php if ( have_posts() ) : ?>

<?php
while ( have_posts() ) : the_post(); 
?>

<?php endwhile; ?>

///Pagination Function in Functions.php
<?php my_pagination(); ?>

<?php else: ?>

    No Results

<?php endif; ?>

Pagination Function

if ( ! function_exists( 'my_pagination' ) ) :
    function my_pagination() {
        global $wp_query;

        $big = 999999999; // need an unlikely integer

        echo 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;

2 Answers
2

This solution needs to be revised for that pagination functions are in functions.php.

I am using Reverie master theme (which uses foundation framework), that theme uses pagination function which is in functions.php

if( ! function_exists( 'reverie_pagination' ) ) {
function reverie_pagination() {
    global $wp_query;

    $big = 999999999; // This needs to be an unlikely integer

    // For more options and info view the docs for paginate_links()
    // http://codex.wordpress.org/Function_Reference/paginate_links
    $paginate_links = paginate_links( array(
        'base' => str_replace( $big, '%#%', get_pagenum_link($big) ),
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'mid_size' => 5,
        'prev_next' => True,
        'prev_text' => __('&laquo;'),
        'next_text' => __('&raquo;'),
        'type' => 'list'
    ) );

    // Display the pagination if more than one page is found
    if ( $paginate_links ) {
        echo '<div class="pagination-centered">';
        echo $paginate_links;
        echo '</div><!--// end .pagination -->';
        }
    }
}

I have revised this function as

    if( ! function_exists( 'reverie_pagination' ) ) {
    function reverie_pagination() {
        global $wp_query, $another_query;

        $big = 999999999; // This needs to be an unlikely integer
        if ( is_front_page()) {
            $myqueryis = $another_query;
            $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
            } else {
            $myqueryis = $wp_query;
            $paged = get_query_var('paged');
            }
        // For more options and info view the docs for paginate_links()
        // http://codex.wordpress.org/Function_Reference/paginate_links
        $paginate_links = paginate_links( array(
            'base' => str_replace( $big, '%#%', get_pagenum_link($big) ),
            'current' => max( 1, $paged ),
            'total' => $myqueryis->max_num_pages,
            'mid_size' => 5,
            'prev_next' => True,
            'prev_text' => __('&laquo;'),
            'next_text' => __('&raquo;'),
            'type' => 'list'
        ) );

        // Display the pagination if more than one page is found
        if ( $paginate_links ) {
            echo '<div class="pagination-centered">';
            echo $paginate_links;
            echo '</div><!--// end .pagination -->';
        }
    }
}

the variable $another_query is my custom WP_Query. This questions author used *query_posts* to get results but I have used *new WP_Query*.

And the query which I have used inside front-page is;

 $args =  array(
            'post_type' => 'post',  
            'post__not_in'   => $do_not_duplicate,
        'paged' => $paged,
            );
 $another_query = new WP_Query( $args );

Leave a Comment