0

Please let me know if anyone know ..

     <?php
                $per_page = 6;
                $paged    = get_query_var('paged') ? : 1;
                $offset   = (1 === $paged) ? 0 : (($paged - 1) * $per_page) + (($paged - 1) * 2);
                
                 $args = array(
                'post_type'=> 'post',
                'posts_per_page' => $per_page,
                'post_status' => 'publish',
                'order' => 'DESC',
                'orderby' => 'ID',
                'paged' => $paged,
                'author__not_in' => array(1),
                'offset' => $offset,
                  'ignore_sticky_posts' => 1
                
                );
                $result = new WP_Query( $args );
                    if ( $result-> have_posts() ) : ?>
                    <?php while ( $result->have_posts() ) : $result->the_post(); ?>
                          
                                    <div class="col-md-4 col-sm-12" style="float:left;">
                                        <div class="authorname">
                                         <?php //geting here post author name
                                            echo get_the_author(); 
                                            
                                          ?>
                                        </div>
                                               <h2 class="post_title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                                                <div class="featured_image">
                                                    <a href="<?php the_permalink() ?>">
                                                        <?php
                                                         the_post_thumbnail('full');
                                                         ?>
                                                     </a>
                                                 </div>
                                                 
                                               <div class="excerpt">
                                                    <?php
                                                     $cats = get_the_category($id);
                                                    
                                                    // excerpt of post
                                                    the_excerpt();
                                                    
                                                    ?>  
                                                    
                                               </div>
                                               <div class="category_name">
                                                   <?php foreach ( $cats as $cat ): ?>
                                                        <a href="<?php echo get_category_link($cat->cat_ID); ?>">
                                                            <?php echo $cat->name; echo ", "; ?>
                                                        </a>
                                                    <?php endforeach; ?>
                                               </div>
                                    </div>
                    <?php endwhile; ?>
                                <!-- Pagination -->
                                <nav class="pagination">
<?php  previous_posts_link('&laquo; Previous', $query->max_num_pages);
if ($paged > 1) echo ' | ';
next_posts_link('More &raquo;', $query->max_num_pages);

echo '<br> Showing ' . $offset . '-' . ($offset + 6) . ' of ' . $query->found_posts . ' posts.';
 ?>
</nav>
                                <!-- pagination ends here -->
                    <?php endif; wp_reset_postdata();  ?>
                   </div> 
                   </div>
            
          <?php
          
          
          ?>

1 Answer 1

0

Change

$paged    = get_query_var('paged') ? : 1;

To

$paged = absint(
    max(
        1,
        get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' )
    )
);

Change

$query

To

$result

Final code

 <?php
                $per_page = 6;

                $paged = absint(
                                           max(
                                                        1,
                                                          get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' )
                                               )
                               );
                
                $offset   = (1 === $paged) ? 0 : (($paged - 1) * $per_page) + (($paged - 1) * 2);
                
                 $args = array(
                'post_type'=> 'post',
                'posts_per_page' => $per_page,
                'post_status' => 'publish',
                'order' => 'DESC',
                'orderby' => 'ID',
                'paged' => $paged,
                //'author__not_in' => array(1),
                'offset' => $offset,
                  'ignore_sticky_posts' => 1
                
                );
                $result = new WP_Query( $args );
                
                    if ( $result-> have_posts() ) : ?>
                    <?php while ( $result->have_posts() ) : $result->the_post(); ?>
                          
                                    <div class="col-md-4 col-sm-12" style="float:left;">
                                        <div class="authorname">
                                         <?php //geting here post author name
                                            echo get_the_author(); 
                                            
                                          ?>
                                        </div>
                                               <h2 class="post_title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                                                <div class="featured_image">
                                                    <a href="<?php the_permalink() ?>">
                                                        <?php
                                                         the_post_thumbnail('full');
                                                         ?>
                                                     </a>
                                                 </div>
                                                 
                                               <div class="excerpt">
                                                    <?php
                                                     $cats = get_the_category($id);
                                                    
                                                    // excerpt of post
                                                    the_excerpt();
                                                    
                                                    ?>  
                                                    
                                               </div>
                                               <div class="category_name">
                                                   <?php foreach ( $cats as $cat ): ?>
                                                        <a href="<?php echo get_category_link($cat->cat_ID); ?>">
                                                            <?php echo $cat->name; echo ", "; ?>
                                                        </a>
                                                    <?php endforeach; ?>
                                               </div>
                                    </div>
                    <?php endwhile; ?>
                    
                                <!-- Pagination -->
                                <nav class="pagination">
<?php  previous_posts_link('&laquo; Previous', $result->max_num_pages);
if ($paged > 1) echo ' | ';
next_posts_link('More &raquo;', $result->max_num_pages);

echo '<br> Showing ' . $offset . '-' . ($offset + 6) . ' of ' . $result->found_posts . ' posts.';
 ?>
</nav>
                                <!-- pagination ends here -->
                    <?php endif; wp_reset_postdata();  ?>
                   </div> 
                   </div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.