I have a custom post type portfolio
and now I'm trying to enable navigation for the template where 10 portfolio items are shown. I'm using the following code to query the posts:
if ( get_query_var('paged') )
{ $paged = get_query_var('paged'); }
elseif ( get_query_var('page') )
{ $paged = get_query_var('page'); }
else
{ $paged = 1; }
$posts_per_page = get_option('posts_per_page');
$offset = ( $posts_per_page * $paged ) - $posts_per_page;
query_posts(array('paged'=>$paged, 'posts_per_page'=> $posts_per_page, 'post_type'=>'portfolio', 'offset' => $offset));
The current link structure is as follows:
domain.com/portfolio //main portfolio page, showing 10 portfolio items
domain.com/portfolio/item //shows a single portfolio item
domain.com/portfolio/page/2 //should show the next set portfolio items, but shows a 404 error instead.
I'm assuming the problem is that when you visit domain.com/portfolio/page/2
that WordPress assumes that page
is a portfolio item, so it looks for that specific portfolio item rather than showing the next portfolio page.
How could I solve this issue? I'd rather not change the link structure for easier browsing.
I do not want to use a plugin like WP Page Navi
, so this is not a duplicate with Pagination not working with custom loop