• Hello i have a problem with my pagination. When i try to visit my second page, it is blank, not even header or footer. Someone have an idea ?

    <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $args = array(
        'post_type'      => 'post',
        'posts_per_page' => 3,
        'paged'          => $paged,
        'orderby'        => 'date',
        'order'          => 'DESC'
    );
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) :
        while ( $query->have_posts() ) : $query->the_post();
            // Afficher les articles ici
            ?>
            <article>
                // my article code
            </article>
            <?php
        endwhile;
        ?>
    
        <!-- Pagination -->
        <div class="pagination">
            <?php echo paginate_links( array(
                'total' => $query->max_num_pages,
                'prev_text' => __( '&laquo;', 'text-domain' ),
                'next_text' => __( '&raquo;', 'text-domain' ),
                'mid_size' => 1
            ) ); ?>
        </div>
        <?php
        // Réinitialiser la requête principale
        wp_reset_postdata();
    else :
        // Aucun article trouvé
    endif; ?>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The page in which this code is used is likely not paginated, so WP thinks any $paged > 1 value is invalid, so in turn your query fails. It’s not a good idea to attempt to reuse $paged for custom queries. It is meant for the main query. If you implement your own unique pagination var you pagination will be much more reliable.

    Simplest would be to use a query string as in example.com/page-name/?my-page=2
    Then in your query args do 'paged' => (int)$_GET['my-page'],
    In paginate_links() you’d also need to add 'current' => (int)$_GET['my-page'],

Viewing 1 replies (of 1 total)
  • The topic ‘Enpty page pagination’ is closed to new replies.