previous_posts_link & next_posts_link doesn’t generate any output

Question

Hey I am using a WPQuery to loop through and show blog categories in posts. It’s in a page tempplate. has 21 posts and I want them to show 10 per page with navigation links for next pages of 10 posts but below code is not outputting that buttons

enter image description here

<div class="container-blog-post d-flex flex-wrap justify-content-start">

        <?php 
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        $args = array(
            'post_type'      => 'post',
            'category_name'  => 'blog',
            'posts_per_page' => 10,
            'orderby'        => 'date',
            'order'          => 'DESC', 
            'paged' => $paged
        );

        $the_query = new WP_Query( $args ); ?>

        <?php if ( $the_query->have_posts() ) : ?>

            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); 


                if(has_post_thumbnail()) {
                    $image = get_the_post_thumbnail_url();
                }else{
                    $image = get_template_directory_uri().'/assets/images/default.svg';
                }                           

                $url   = get_permalink();
                $title = get_the_title();
                $text  = excerpt(20);
                $date = get_the_date();

            ?>
                
              <a href="<?php echo $url; ?>" class="single-post card">
                <figure class="image-wrapping">
                  <img src="<?php echo $image; ?>" alt="">
                </figure>
                <div class="body-post card-body">
                  <h3 class="title-post card-title"><?php echo $title; ?></h3>
                  <p class="card-text line-clamp-2"><?php echo excerpt(10); ?></p>
                  <button class="btn-read-more arrow">Read more</button>
                  <div class="button-post">
                    <span class="date-post"><?php echo $date; ?></span><span class="author-post"><?php echo the_author(); ?></span>
                  </div>
                </div>
              </a>  

            <?php endwhile; ?>
        
            <div class="previous">
                <?php previous_posts_link(); ?>
        </div>
        <div class="next">
            <?php next_posts_link(); ?>
        </div>
            <?php wp_reset_postdata(); ?>
        <?php endif; ?>  

    </div>
0
Ashish Jat 2 years 2020-10-24T19:10:28-05:00 0 Answers 16 views 0

Leave an answer

Browse
Browse