I have index.php
with a pagination. The permalink settings is plain permalinks.
I have a correct pagination view when I open a page /?paged=2
but if I open just index.php
I have all posts without pagination. There is my 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();?>
PS: I just edit my code like that but nothing was changed. The first page displays all posts without pagination
<?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(); ?>
I have index.php
with a pagination. The permalink settings is plain permalinks.
I have a correct pagination view when I open a page /?paged=2
but if I open just index.php
I have all posts without pagination. There is my 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();?>
PS: I just edit my code like that but nothing was changed. The first page displays all posts without pagination
<?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(); ?>
Share
Improve this question
edited Aug 4, 2017 at 9:14
Johansson
15.4k11 gold badges43 silver badges79 bronze badges
asked Dec 20, 2015 at 1:13
Sergei RodionovSergei Rodionov
117 bronze badges
2
|
2 Answers
Reset to default 1Adding ignore sticky line inside array should solve the issue :)
$args = array(
'post_type' => 'post',
'posts_per_page' => '6',
'ignore_sticky_posts' => 1,//this is the one :)
'paged' => $paged,
);
Add this two lines to your theme's function.php file and everything will get back to work:
add_filter(‘redirect_canonical’,’custom_disable_redirect_canonical’);
function custom_disable_redirect_canonical($redirect_url) {if (is_paged() && is_singular()) $redirect_url = false; return $redirect_url; }
pre_get_posts
to alter the main query. Also,the_posts_pagination()
only works with the main query, it doesnot work with custom queries, except if you hack the main query – Pieter Goosen Commented Dec 20, 2015 at 5:10