WordPress - Each page of paged posts all show same posts - wordpress

I set up a pagination function for my wordpress blog. When clicking to the next page, the URL is correct: "/page/1", "/page/2", "/page/3" etc, but the actual posts don't change from page to page (page 2 and page 3 still display the first page of posts). Here's the code I'm using for the loop:
Edit 4/24/10: I removed the 'offset' => 1, parameter and the paging now works, but now the question becomes: how do I use the offset parameter and still page?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky=get_option('sticky_posts');
$args=array(
'offset' => 1,
'category__not_in' => array(-6),
'paged'=>$paged,
'showposts' => 6,
);
query_posts($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
Any help/insight would be much appreciated. Thank you!

I removed the 'offset' => 1, parameter and the paging now works, but now the question becomes: how do I use the offset parameter and still page?

See How to: Offsets and Paging « Weblog Tools Collection and WordPress › Support » Query_posts, offset and pagination

Related

WordPress index archives not working (Prev / Next)

I'm having a strange issue whereby my blog index archives pages (Previous Link) isn't working and is going to a 404 page.
I have a page set as the site's Index, and the News (Blog) section is located at a seperate page called 'news'. Archive pagination works fine for category archives, it just appears to be the index.php loop that is not allowing the archives pagination to work for some reason. Any help would be greatly appreciated, here's my code from my theme's index.php file that dips into the loop for posts:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
// 'cat' => -13, // Exclude Guide To's
'order' => 'DESC',
'paged' => $paged,
'ignore_sticky_posts' => true
);
$latest_posts = new WP_Query( $args );
if ( $latest_posts->have_posts() ) {
while ( $latest_posts->have_posts() ) {
$latest_posts->the_post(); ?>
<?php get_template_part( 'content', 'post' ); ?>
<? } }
?>
If I understand you correctly, you have set a static front page. In that case
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
is wrong. paged is used for any page, except a static front page. Static front pages uses page. So you should change the above mentioned line to
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
EDIT
Your next_posts_link should also be adjusted for custom queries. You have to set the $max_pages parameter
next_posts_link( 'Older Entries', $latest_posts->max_num_pages );
EDIT 2
Seems like your rewrite rules seems to be the problem. Add the following to your functions.php and reload your index page a few times.
function bt_flush_rewrite_rules() {
flush_rewrite_rules();
}
PLEASE NOTE You should delete this function immediately after reloading your index page a few times. flush_rewrite_rules() are a really expensive operation that is quite tough on resources, so it should ONLY be used if really really necessary

How to get pagination working with “Pending” Posts

I'm working on a site that allows users to browse through pending posts/content on the front-end.
However, I can't seem to get pagination working with those posts. I've got a custom query that brings up the first page of pending posts on a category page, archive, etc.
But the Page 2, 3, etc. doesn't work.
Any thoughts?
Thanks!
Here's the example code I'm working with:
$args = array(
'cat' => $cat_ID,
'paged' => get_query_var('paged'),
'showposts' => 50,
'posts_per_page' => 50,
'post_status' => 'pending',
);
query_posts($args);
if( have_posts() ) : while (have_posts()) : the_post();
//Post code inserted here
<?php endwhile; ?>
<?php endif; ?>
WordPress pagination will 404 if there are not enough results in the main query to run to that page.
I'm sure there is a better way, but the only way I can think of round it is to use your custom loop in an archive/search page that has more posts than you have drafts.
For example, add your custom loop to the search.php template and reach it by passing a search query that will generate lots of results (e.g. 'a'). Using search.php will include pages, posts and custom post types in the results so will yield more results.
Use paginate_links for the pagination, which will continue to pass the queryvar on each page and after that you should be good.
On a slightly separate note, I would suggest using WP_Query instead of query_posts. See here for why.

Page url showing page/2 but getting posts from first page

I'm struggling a theme that I got, the theme uses query_posts() and pagination used to work. Now pagination is not working on this page, and it keeps on showing posts from the first page on the second. Meaning, the url shows page/2 but I keep on seeing the first posts of the category, i.e. the first 4 on every page.
Here is the code used to get the posts:
global $current_category;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
global $query_string;
$args = "";
if ($current_category['post_type'] == "product") {
$args=array(
'showposts' => 4,
'paged' => $paged,
'post_type' => 'product'
);
} else {
$args=array(
'showposts' => 4,
'category_name' => $current_category['name'],
'paged' => $paged
);
}
query_posts($args);
And here's the loop:
if (have_posts()) : while (have_posts()) : the_post();
<outputs code here>
endwhile;
else :
<output no results code here>
endif;
if ( is_home() ) wp_reset_query();
Now, can anybody please point me in the right direction?
//update:
I have already tried this solution as well, so far, I can only tell that the paged variable never gets updated in the query.
//update 2:
This page was done custom, and setting it as the home page via Settings -> Reading inhibits the above behaviour. When leaving it as a normal page, and setting home as recent posts, the pagination works fine.
if you have any custom queries in the template, make sure to integrate the 'paged' parameter.
Pagination Parameters
Go through these codex pages:
Preserving Existing Query Parameters
Related: Pagination
I have fixed this after some very long research. My code now looks as follows:
global $current_category, $paged;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
This just replaces the first 3 lines of the original code in the answer. The rest looks exactly the same.

Problem with Categories in Wordpress!

My Original question was this:
I have a wordpress installation where
the Home page is set to display post
from a specific category. To achieve
this, I created a template "home.php"
and put the following code:
query_posts( 'cat=4&order=desc' );
When I visit the site's home page, it
display posts from the category but
the Navigation does not work? I have
permalink structure set
"/%category%/%postname%/"
Please let me know if I am doing
something wrong.
Update:
Now, I have solved this using this code:
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array (
'cat' => 4,
'orderby' => 'date',
'order' => 'desc',
'posts_per_page' => '10'
);
query_posts($args . '&paged=' . $paged);
Now the problem is that first time, it displays everything fine but if you visit any other archive page, it start displaying posts from other categories. For example, the above code displays posts from Cat=>3 as well. And on page, where I want to display posts from Category = 3, it display posts from category 4 as well.
Please help...
Thanks
What do you mean by "Navigation"? What code are you using for the navigation? Are you limiting the amount of posts?
If you have problems with the pagination. You can use this:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=4&order=desc&paged=$paged"); ?>
Please, Clarify your problems to help you.

$paged do not work in wordpress frontpage

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 10,
'paged' => $paged,
);
query_posts($args);?>
I used this code in WP page template, then published a page with this template, then set this page as static homepage, then I find paged always equals 1.
when I click page 2, I still get same content as page 1, although url is correct ,such as /page/2/
i find the answer myself.
just use
get_query_var('page')
instead,it will work.

Resources