Paginate Custom Post Type Page

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)

<?php
/*
Template Name: Portfolio
*/
?>

<?php get_header(); ?>
<div id="container">
<div id="portfolio_content">
<div id="portfolio_wrap">

    <?php $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => get_option('to_count_portfolio'), 'paged' => get_query_var('paged') ? get_query_var('paged') : 1 )
); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <span class="title"><?php the_title(); ?></span></br>
        <?php endwhile; ?>  

<?php

$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' => $loop->max_num_pages
) );
?>
</div>
</div>
</div>
</div>

<?php get_footer(); ?>

Leave a Comment