我有index.php
使用分页。永久链接设置为普通永久链接。
打开页面时有正确的分页视图/?paged=2
但如果我打开index.php
我所有的帖子都没有分页。这是我的index.php
:
<?php get_header(); ?>
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$posts_per_page = get_option(\'posts_per_page\');
$args = array(\'post__in\' => get_option( \'sticky_posts\'
),\'posts_per_page\' => $posts_per_page, \'paged\' => $paged);
$the_query = new WP_Query( $args);
if ( $the_query->have_posts() ) : ?>
<div class="section">
<div class="container">
<div class="wrap-content">
<div class="pg-block list">
<?php
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part( \'content\', get_post_format() );
endwhile;
?>
</div>
<?php wp_reset_postdata(); ?>
<aside class="wrap-aside hid-xs">
<div class="block-inner">
<?php dynamic_sidebar(\'sidebar-1\');?>
</div>
</aside>
</div>
<div class="wrap-content">
<?php
//number of pages for pagination
$total_pages = $the_query->found_posts / $posts_per_page;
if ($the_query->found_posts % $posts_per_page != 0) $total_pages++;
$args_nav = array(
\'show_all\' => false,
\'end_size\' => 2,
\'mid_size\' => 2,
\'prev_next\' => True,
\'prev_text\' => \'\',
\'next_text\' => \'\',
\'total\' => $total_pages,
\'add_args\' => False,
\'add_fragment\' => \'\',
\'screen_reader_text\' => \' \'
);
the_posts_pagination($args_nav);
?>
</div>
</div>
</div>
<?php else : ?>
<p><?php _e( \'Posts not found\' ); ?></p>
<?php endif;
get_footer();?>
附言:我只是像那样编辑我的代码,但什么都没有改变。第一页显示所有未分页的帖子
<?php if ( have_posts() ) : ?>
<div class="section">
<div class="container">
<div class="wrap-content">
<div class="pg-block list">
<?php
while ( have_posts() ) : the_post();
get_template_part( \'content\', get_post_format() );
endwhile;
?>
</div>
<?php wp_reset_postdata(); ?>