I'm trying to configure the Wordpress pagination in de Index homepage.
I've used the WP_Query with the regard of get_query_var('paged') before, just as the code shows:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'cat' => 7,
'posts_per_page' => 2,
'paged' => $paged
) );
?>
Then I used the native Wordpress function previous_posts_link() to go back onte the list of posts.
The problem that happens is that when the page loads, the url of the page changes, but the posts that shows are the same as before. Even to page 3 or 4, it just shows the same list of pages.
Where am I going wrong?
Related
I have woocommerce set up in a site and it has an ajax switch. With this the view of products changes from list to grid and vice versa. In the ajax call, I have queried the products again through a custom query using this code
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'product',
'posts_per_page' => 20,
'product_cat' => $_GET['category'],
'paged' => $paged
);
$count = 0;
$loop = new WP_Query( $args );
But I dont get the required output from get_query_var(10). The url of the product page is as follows.
https:example.com/product-category/producers/arturo/page/2/?view=grid
Through this url all I need is the page parameter with value 2. How can I fetch it in the ajax call.
Currently I am trying to get wordpress pagination to display at the bottom of the page but nothing shows up, if I echo out "paged" it outputs 1 so I believe it is correctly reading the page it is on. The loop I am using is as follows:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'company_list', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 6, 'paged' => $paged);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
To echo out the actual pagination at the bottom of the page I am using:
echo paginate_links( $loop );
Currently no pagination is being displayed at the bottom of the page but the loop is working correctly. The page is also not set as a static front page.
Thanks.
1)You do not have to use question mark in your first row
$paged = (get_query_var('paged')) ?
2)also see :
https://stackoverflow.com/a/33757648/10210277
Pagination on my website not working, everything else is fine, But when i click to go to "/page/2/3/" it shows no page found error.
Website : http://savemoney.16mb.com
Error pages: http://savemoney.16mb.com/page/2/
and currently Front Page set to "Latest Posts" (Not Static Page)
Pagination Code (Frontpage.php):
<?php
// show all coupons and setup pagination
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts( array( 'post_type' => APP_POST_TYPE, 'post_status' => $post_status, 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
?>
<?php get_template_part('loop', 'coupon'); ?>`
Any advice on how to get this pagination working correctly would be appreciated!
Thanks,
T
have you tried , "add_args" => false ?
here is more info for that https://core.trac.wordpress.org/ticket/30831
I have a custom query that uses an array merge so I can list articles and custom post type posts in one list, showing 5 at a time. Pagination below allows the user to see the rest of the results. I keep getting pagination errors, but I've tried virtually every variation of the $paged variable in my query to get pagination to work and it doesn't. I know it's me, and probably a simple syntax thing...but I'm stumped. Any ideas? (Note: this page has multiple, other custom queries above the one in question)
Here's my code:
<?php
$loop1 = array_merge( $wp_query->query,
array( 'post_type' => array('post','podcasts', 'cat' => $cat_ID ),
'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
'posts_per_page' => 5 ) );
query_posts( $loop1 );
while (have_posts()) : the_post(); ?>
have you tried?
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
With wordpress I am trying to figure out how to get the current page number and use it with the query_posts function i have tried passing in page=1 but that doesnt seem to work
query_posts( "cat=4&posts_per_page=1" ); // how do i pass in the page number???
query_posts( array( 'cat' => 8, 'posts_per_page' => 25, 'paged' => get_query_var('page') ) );