I have a website where On the home page I show all the posts of the website but now the requirement is to show all the posts excluding 3 Categories, but when I updated my WP_Query accordingly, Now Pagination started showing posts in loop, so Right now I am showing 12 posts in one page, so after 12 posts it repeats from the first post again and so one (right now my pagination is linked with infinite scroll but even if I disable infinite scroll, and switch to normal pagination, the issue still remains.
Below is my custom query
$fullquery = new WP_Query( 'cat=-12,-34,-56' );
while ($fullqury->have_posts()) : $fullqury->the_post();
And Below is my Pagination Code
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $fullquery->max_num_pages
) );
?>
Try this
I'm not use the WP native pagination.
Actually I emptied the code in pagination.php
In your template.php, where you want to place your pagination
<div class="row">
<div class="col-md-12">
<div class="pagination">
<?php pagination_bar( $loop ); ?>
</div>
</div>
</div>
In the same template in the loop add :
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
And in your function.php (theme child)
// Pagination
function pagination_bar( $custom_query ) {
$total_pages = $custom_query->max_num_pages;
$big = 999999999;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
));
}
}
// END Pagination
It works for me
Related
PRECONDITION:
I created post type 'comparison'.
I created archive page for 'comparison' post type only.
TASK: I need to create pagination at archive page of 'comparison'.
PROBLEM: I tried to use
<?php echo paginate_links(); ?>
but it doesn't work, pls help.
Try the following code
$query = new WP_Query(
array(
'posts_per_page'=>30,
'post_type'=>'comparison',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1
)
);
?>
<?php while ($query -> have_posts()) : $query -> the_post(); ?>
//your code
endwhile;
$total_pages = $query->max_num_pages;
if ($total_pages > 1){
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $query->max_num_pages
) );
}
wp_reset_postdata();
I am using pagination in wordpress category.php page. everthing is fine but when I click to next page i got following error
Template is missing. Standalone themes need to have a index.php template file. Child themes need to have a Template header in the style.css stylesheet.
My url is some thing like
https://test.com/category/cat_name/page/2/
Here is my code:
$cat_name = $category->name;
$cat_id = get_cat_ID( $cat_name );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=1&post_type=post&paged='.$paged.'&cat='.$cat_id);
while ($wp_query->have_posts()) : $wp_query->the_post();
/// loop here
<?php endwhile; ?>
Code for pagination:
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo '<div class="custom-pagination">';
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_text' => __('Previous'),
'next_text' => __('Next'),
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
echo '</div>';
?>
Should I add some code in htaccess file or function.php for redirect in category.php?
I got the answer by my self. I need to change the Blog pages show at most in reading section of Dashboard. I set same number of showposts i.e 1 in Blog pages show at most.
I can add numbered pagination to wordpress fine, the problem is when I click on page two the link for page one doesn't appear to be clickable. The loop still thinks it's on page one.
This is my current code.
<?php query_posts('posts_per_page=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
....
<?php endwhile;
endif; ?>
<?php
global $wp_query;
$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, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
In my wordpress blog, i use wp paginate (default plugin) for pagination. I use a custom query to list the posts. Please see this link
Everything works fine. I show six posts per page (admin setting) and the number of pages are correct. But my problem is all the pages are shown in the pagination.
i.e. 1|2|3|4|5|6|7|8|9|10|>, but I want it like this |1|2|3|4|...|10|>.
What should I do, I'm new to wordpress. Can anyone help please?
Note:
No modifications done to wp paginate plugin.
Also changed the pagination settings in backend (wp-admin) to show 3 pages front and back of the current page and it doesn't work.
my index.php looks like this:
<?php
$paged = get_query_var('paged');
$args = array(
'post_type' => 'post',
'meta_key' => 'wpcf-fn',
'orderby' => 'meta_value',
'order' => 'ASC',
'paged' => $paged
);
$cust_query = new WP_Query( $args );
$temp = $wp_query;
$wp_query = $cust_query;
?>
<div> *** contents rendered on the page *** </div>
<div id="navigation" class="clearfix">
<?php if(function_exists('wp_paginate')) : wp_paginate(); ?>
</div>
<?php $wp_query = $temp;?>
<?php
global $wp_query;
$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, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'show_all' => FALSE, //this will make paginate not to show all links.
'end_size' => 2, //will show 2 numbers on either the start and the end list edges.
'mid_size' => 0 //so that you won't have 1,2...,3,...,7,8
) );
?>
More details: https://developer.wordpress.org/reference/functions/paginate_links/
I am using Wordpress and a static homepage and a posts page to display all my news posts located here: http://www.bigideaadv.com/uptous/?page_id=13
The pagination only works on page 1 and 2. Page 3 causes errors. Also, if I try and add more posts, the pagination doesn't go above three pages.
Does anyone have any thoughts?
Posts query to follow:
$posts = query_posts($query_string.'&orderby=title&order=asc&posts_per_page=4&paged='.$paged);
Here is a simple way to do pagination without any plugin :
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
Put it in your index.php and it should works !