“Broken” Pagination

On my WordPress site, I have pagination working for a Custom Post Type. When I say working, I mean the pagination is appearing. Whenever I attempt to go to page 2 for example, I get a 404 error. I’ve got a very similar code snippet that works perfectly fine on blog posts. Any Suggestions? The code is below:

    <?php
/**
 * @package WordPress
 * @subpackage themename
 * Template Name: Resources Template
 */

get_header(); ?>
<div id="main">
        <div id="primary">
            <div id="content">

                <?php the_post(); ?>

                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">

                        <h1 class="entry-title"><?php the_title(); ?></h1>

                    <div class="entry-content">
                        <?php the_content(); ?>
                        <?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'cbd_resources', 'posts_per_page' => 5, 'paged' => $paged); // -1 Shows ALL Posts
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>

                        <?php
$resourceURL = get_post_meta($post->ID,'resourceURL',true);
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
$imgURL = (isset($thumb[0]) ? $thumb[0] : get_template_directory_uri() . "/images/placeholder.jpg"); ?>


                        <div class="testimonialListing">
                            <img src="<?php echo get_template_directory_uri(); ?>/thumb.php?src=<?php echo urlencode($imgURL); ?>&w=127&zc=2">
                            <div class="testimonialInfo">
                                <span><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
                                <?php the_content(); ?>
                                <strong><a href="<?php the_permalink(); ?>">READ MORE</a></strong>
                            </div>
                        </div>

                        <?php endwhile; ?>


                    <?php wp_reset_query(); ?>
                        <div class="pagination">
                        <?php $total_pages = $loop->max_num_pages;

if ($total_pages > 1){

    $current_page = max(1, get_query_var('paged'));

    echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
}   ?>
                        </div>
                                            </div><!-- .entry-content -->
                </article><!-- #post-<?php the_ID(); ?> -->



            </div><!-- #content -->
            <div id="secondary" class="widget-area"><?php if ( dynamic_sidebar('resources-sidebar') ) : else : ?><?php endif; ?></div>
        </div><!-- #primary -->


<?php get_footer(); ?>

Related posts

Leave a Reply