php – Pagination contents not changing in Front page WordPress

Question

Found the solution. Is anybody facing the same please check this.

My code is right, but because of the offset parameter pagination is not working. I found the solution here.

So, this is my final code:

<?php
    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

    $per_page = 10;
    $defualt_offset = $offset;

    if ($paged == 1) {
        $offset = $default_offset;
    } else {
        $offset = (($paged - 1) * $per_page) + $default_offset;
    }

    $args = array(
        'post_type'=>'post', 
        'posts_per_page'=>$per_page, 
        'orderby'=>'date', 
        'order'=>'DESC', 
        'offset'=>3, 
        'paged'=>$paged
    );

    $blogs = new WP_Query($args);
    if($blogs->have_posts()):
        while($blogs->have_posts()): $blogs->the_post();
?>

    <div class="col-md-6">
        <div class="single-post">
            <div class="thumb">
                <a href="<?php the_permalink(); ?>">
                    <img src="<?php the_post_thumbnail_url('blog-thumbnail'); ?>" alt="<?php the_title(); ?>" class="img-fluid" />
                </a>
            </div>
            <div class="content">
                <div class="category">
                    <?php
                    $categories = get_the_category();
                    foreach ($categories as $key => $category) {
                        echo '<a href="' . get_category_link($category->term_id). '">'. $category->name. '</a>';
                    }
                    ?>
                </div>
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <div class="metadata">
                    <span class="date"><?php echo get_the_date(); ?></span>
                    <span class="author"><?php echo get_the_author(); ?></span>
                </div>
                <div class="excerpt">
                    <?php the_excerpt(); ?>
                </div>
            </div>
        </div>
    </div>

<?php
        endwhile;
        echo '<div class="paginate-wrap">'. paginate_links() . '</div>';
    endif;
    wp_reset_query();
?>

0
user2584538 2 weeks 2021-09-05T01:04:49-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse