改变
$paged = get_query_var(\'paged\') ? : 1;
至
$paged = absint(
max(
1,
get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : get_query_var( \'page\' )
)
);
更改
$query
至
$result
最终代码
<?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(\'« Previous\', $result->max_num_pages);
if ($paged > 1) echo \' | \';
next_posts_link(\'More »\', $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>