0
votes

can anyone please help me with my pagination.As in wordpress when I assign a static page as front page it is not working.Please check the link.

2
can you please show me the php code of static page. ? - GKS
Thanks for your help.but it is not working. - arc_shiva
@Govind Kumar,Which page are you talking about?I am not getting.Please clear. - arc_shiva
Please try my answer , - GKS
where is the answer? - arc_shiva

2 Answers

0
votes

Add this code inside your Theme's functions.php file.

The pre_get_posts action gives developers access to the $query object by reference (any changes you make to $query are made directly to the original object - no return value is necessary).

add_action('pre_get_posts', function ($query) {

    if ($query->is_main_query() && is_front_page()) {

        // get the page query string value.
        $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

        // set current page query string.
        $query->set('paged', $paged);

        // set posts_per_page 
        $query->set('posts_per_page', 9); // remove if already assigned.
    }

});

Reference: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

0
votes

Instead of doing this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

I do this:

if ( get_query_var('paged') ) {

    $paged = get_query_var('paged');

} elseif ( get_query_var('page') ) {

    $paged = get_query_var('page');

} else {

    $paged = 1;

}