wordpress Static Page pagination

4.6k Views Asked by At

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

There are 2 best solutions below

0
On BEST ANSWER

Wordpress Static front page Pagination after a lot of Searches and googling i fix it by using

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array('post_type'=>'cover','posts_per_page'=>2,'paged'=>$paged);


query_posts($args);
0
On

I've found a small error in Youssef Subehis solution. It is missing a "d" in "paged" here get_query_var('page'). This fixed the wordpress page pagination problem for me:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page'=>10,'paged'=>$paged);

query_posts($args);

This is referecend in the official wordpress documentation here.