wordpress pagination category 404 on page 2
When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:
<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>
<!-- end pagination-->
</ul>
php html wordpress
add a comment |
When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:
<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>
<!-- end pagination-->
</ul>
php html wordpress
What do you mean by "other side of pagination" and "throw out the page 404"?
– zipkundan
Nov 14 '18 at 16:21
Sorry, now i edit my question.
– Stefan Loncaric
Nov 14 '18 at 16:44
Are you using child theme?
– Gufran Hasan
Nov 14 '18 at 17:08
add a comment |
When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:
<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>
<!-- end pagination-->
</ul>
php html wordpress
When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:
<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>
<!-- end pagination-->
</ul>
php html wordpress
php html wordpress
edited Nov 14 '18 at 18:32
Gufran Hasan
3,57241426
3,57241426
asked Nov 14 '18 at 15:29
Stefan LoncaricStefan Loncaric
125
125
What do you mean by "other side of pagination" and "throw out the page 404"?
– zipkundan
Nov 14 '18 at 16:21
Sorry, now i edit my question.
– Stefan Loncaric
Nov 14 '18 at 16:44
Are you using child theme?
– Gufran Hasan
Nov 14 '18 at 17:08
add a comment |
What do you mean by "other side of pagination" and "throw out the page 404"?
– zipkundan
Nov 14 '18 at 16:21
Sorry, now i edit my question.
– Stefan Loncaric
Nov 14 '18 at 16:44
Are you using child theme?
– Gufran Hasan
Nov 14 '18 at 17:08
What do you mean by "other side of pagination" and "throw out the page 404"?
– zipkundan
Nov 14 '18 at 16:21
What do you mean by "other side of pagination" and "throw out the page 404"?
– zipkundan
Nov 14 '18 at 16:21
Sorry, now i edit my question.
– Stefan Loncaric
Nov 14 '18 at 16:44
Sorry, now i edit my question.
– Stefan Loncaric
Nov 14 '18 at 16:44
Are you using child theme?
– Gufran Hasan
Nov 14 '18 at 17:08
Are you using child theme?
– Gufran Hasan
Nov 14 '18 at 17:08
add a comment |
2 Answers
2
active
oldest
votes
You need to modify query as:
$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);
For pagination, I changed this code like this. Hope this will help you:
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
add a comment |
I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!
Thanks man! Gufran Hasan
Code:
function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303608%2fwordpress-pagination-category-404-on-page-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to modify query as:
$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);
For pagination, I changed this code like this. Hope this will help you:
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
add a comment |
You need to modify query as:
$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);
For pagination, I changed this code like this. Hope this will help you:
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
add a comment |
You need to modify query as:
$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);
For pagination, I changed this code like this. Hope this will help you:
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));
You need to modify query as:
$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);
For pagination, I changed this code like this. Hope this will help you:
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));
answered Nov 14 '18 at 17:11
Gufran HasanGufran Hasan
3,57241426
3,57241426
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
add a comment |
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
Again same, page 404 :/
– Stefan Loncaric
Nov 14 '18 at 17:22
add a comment |
I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!
Thanks man! Gufran Hasan
Code:
function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
add a comment |
I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!
Thanks man! Gufran Hasan
Code:
function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
add a comment |
I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!
Thanks man! Gufran Hasan
Code:
function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!
Thanks man! Gufran Hasan
Code:
function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
answered Nov 14 '18 at 17:40
Stefan LoncaricStefan Loncaric
125
125
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
add a comment |
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Now it's working?
– Gufran Hasan
Nov 14 '18 at 17:54
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
Yea, thank you man :)
– Stefan Loncaric
Nov 14 '18 at 18:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303608%2fwordpress-pagination-category-404-on-page-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by "other side of pagination" and "throw out the page 404"?
– zipkundan
Nov 14 '18 at 16:21
Sorry, now i edit my question.
– Stefan Loncaric
Nov 14 '18 at 16:44
Are you using child theme?
– Gufran Hasan
Nov 14 '18 at 17:08