I created a page for my custom post types. The code can be viewed on Snippi: http://snippi.com/s/e8852rx
I’m trying to insert paginate_links, but for whatever reason it’s simply not showing up. Here is the paginate_links code (this code works on normal archive.php files):
<?php
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
) );
?>
The following works for me (I’ve removed all the formating / custom post meta).
I would add, its not clear why you need to use a page with a custom template, and don’t instead create a template called
archive-portfolio.php
which is used for a custom post type’s archive pages (see template hierarchy)Instead of using the “$loop->have_posts()” approach, like Stephen Harris pointed, you can also try looping the posts like this:
Have you tried using the portfolio post type root archive page?
If you move most of your code into an archive-portfolio.php file, then the loop should be setup correctly and paging should work out of the box, with no funky functions, or hacks or kludges, just like it does on post archives.
It also means you don’t need to use you’re own custom query, just use the main loop instead, making the page load faster
You are refernecing the main query, so it’s likely that it’s trying to show ‘posts’ only, as opposed to your custom post type.
Not sure what your exact format is, but I’d redo the query so –
This means that your code would become –
This is a problem I have struggled with on plenty of occasions.
Here’s what has worked for me in this situation (WP 3.1.1):
Then, for the pagination controls:
It would be better to create a function within your functions.php file that handles pagination and can be used throughout your theme, for standard, and custom post types.
With the following function dropping
get_pagination()
into your theme will give you navigation where-ever you need it. I wrote a blog post on it here: http://deadlyhifi.com/2011/06/non-bloated-pagination-for-your-wordpress-functions-php-file/ (and the code is based on http://robertbasic.com/blog/wordpress-paging-navigation/ originally)I’ve never had a problem using pagination on a custom archive.
So, instead of making a page and then writing my own query on it, just copy/paste
archive.php
and rename it match your custom post, egarchive-videos.php
.If you really want to use custom page template, add this just before your query:
More info: http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html