在我的WordPress网站上,我有自定义帖子类型的分页。当我说工作时,我的意思是分页出现了。每当我尝试转到第2页时,我都会收到404错误。我有一个非常相似的代码片段,可以在博客文章中完美地运行。有什么建议?代码如下:
<?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(); ?>