admin管理员组文章数量:1318991
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('« Previous', $query->max_num_pages);
if ($paged > 1) echo ' | ';
next_posts_link('More »', $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
?>
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('« Previous', $query->max_num_pages);
if ($paged > 1) echo ' | ';
next_posts_link('More »', $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
?>
Share
Improve this question
edited Oct 18, 2020 at 8:11
Valerii Vasyliev
4142 silver badges9 bronze badges
asked Oct 18, 2020 at 6:46
Pankaj YadavPankaj Yadav
11 bronze badge
1 Answer
Reset to default 0Change
$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('« 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>
本文标签: Wordpress blog pagination not working
版权声明:本文标题:Wordpress blog pagination not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742053511a2418172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论