Custom Posts & Pagination?
-
I know this has been asked a million times, I spent all day yesterday researching how to implement pagination.
I finally understand it for the most part, when it comes down to the custom post type I am running into confusion, I hope someone can clarify it for me.
The reason I am creating a new topic is because I want to find a solution based on the code I have.
Here is some snippets of the code inside my 2 column portfolio template, yes this is pagination for portfolio type posts.
<?php $loop = new WP_Query(array( 'post_type' => 'project', 'posts_per_page' => 2)); $count =0; ?>So this is a variable that controls how many posts to display, for testing I set it to 2. As for pagination I am using kriesi_pagination and that code is in my functions.php and is called inside the template
<?php kriesi_pagination($loop->max_num_pages, $range = 2); ?>I added the $loop variable and pagination appears on the page, but as the issue I was having yesterday page 2 shows the same posts, so the solution was to add
<?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } $blog = new WP_Query('posts_per_page=3&paged=' . $paged); ?>So I added this to my portfolio template changing the $blog variable to $loop also inter-grading the array inside the WP_Query. Like so:
<?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } $loop = new WP_Query(array( 'post_type' => 'project', 'posts_per_page=3&paged=') . $paged); ?>The code above displays my blog posts, and not my portfolio posts.
Any shed of light would be amazing, I know I have to be close to getting it to work properly, but I am still missing something.
2nd post – moved by moderator to here: Was my post clear enough? If not I can reiterate.
[You’re more likely to get answered if you don’t bump – http://codex.ww.wp.xz.cn/Forum_Welcome#No_Bumping ]
The topic ‘Custom Posts & Pagination?’ is closed to new replies.