【发布时间】:2018-05-19 10:31:04
【问题描述】:
我正在我的自定义主题 wordpress 中创建一个博客页面,我想在我的列表帖子中使用分页,我的帖子列表查询效果很好,但分页不起作用。我看到的前 2 个帖子总是一样的。
page-blog.php
/*
* Template Name: Pagina Blog
*/
<?php get_header(); ?>
<?php
$posts_per_page = 2;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
//$posts_array = get_posts( $args );
$wp_query = new WP_Query( $args );
//query_posts( $args );
?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- Title -->
<h1 class="my-4"><?php the_title() ?></h1>
<h2 class="card-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<!-- Content -->
<?php the_content() ?>
<!-- Pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php endwhile;
// Reset Query
wp_reset_query(); ?>
<?php get_footer(); ?>
我认为循环存在一些问题,但我不确定,我可以看到“较新”和“较旧”链接,但是当我继续较旧时,我会看到相同的帖子,所以“www.mysite.com/ blog”与“www.mysite.com/blog/2”有相同的帖子:(
【问题讨论】:
标签: php wordpress pagination