Pagination (on the static front page) shows always the same posts

admin2025-01-08  3

I have a problem with pagination on my front page. I want to show all posts from a specific category and paginate them. Here is the code

if ( is_front_page() ) {    
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
    $args = array(
        'post_type'      => 'post',
        'orderby'        => 'date',
        'order'          => 'DESC',
        'posts_per_page' => 1,
        'cat'            => '4',
        'page'           => $paged,
    ); 
    $q = new WP_Query( $args );
    if ( $q->have_posts() ) { 
        while ( $q->have_posts() ) {
            $q->the_post();
            ?>
            <div> .... </div>
            <?php
        }
        //pagination links
        wp_reset_query();
    }
}

But all the time I have the same posts on different pages: domain/page/2/ etc. What I'm doing wrong? How to fix it?

Thank you for any help.

I have a problem with pagination on my front page. I want to show all posts from a specific category and paginate them. Here is the code

if ( is_front_page() ) {    
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
    $args = array(
        'post_type'      => 'post',
        'orderby'        => 'date',
        'order'          => 'DESC',
        'posts_per_page' => 1,
        'cat'            => '4',
        'page'           => $paged,
    ); 
    $q = new WP_Query( $args );
    if ( $q->have_posts() ) { 
        while ( $q->have_posts() ) {
            $q->the_post();
            ?>
            <div> .... </div>
            <?php
        }
        //pagination links
        wp_reset_query();
    }
}

But all the time I have the same posts on different pages: domain.com/page/2/ etc. What I'm doing wrong? How to fix it?

Thank you for any help.

Share Improve this question edited Feb 28, 2018 at 21:33 obiPlabon 1,7297 silver badges13 bronze badges asked Feb 28, 2018 at 16:53 Ante MedicAnte Medic 693 silver badges12 bronze badges 2
  • Please add your pagination code as well. – obiPlabon Commented Feb 28, 2018 at 18:02
  • I was adding pagination code, and redone it from scratch and now is working. Thanks! – Ante Medic Commented Feb 28, 2018 at 19:15
Add a comment  | 

1 Answer 1

Reset to default 0

https://codex.wordpress.org/Creating_a_Static_Front_Page

Static front pages are not intended to be paged. None of the WordPress Previous / Next page link functions work with a static front page. Pagination on a static front page uses the page query variable, not the paged variable. See the WP_Query for details.


https://codex.wordpress.org/Class_Reference/WP_Query

Display posts from current page on a static front page:

$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query = new WP_Query( array( 'paged' => $paged ) );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736267262a1183.html

最新回复(0)