问题描述
我正在开发自定义wordpress主题。在此之前,第2页的分页链接显示404错误,但我设法以某种方式修复了该错误,但是现在单击第2页没有任何作用。它卡在第1页上。这是我第一次尝试从头开始开发自定义主题。非常感谢您的帮助。
这是我的category.PHP
<?PHP
get_header();
$currCat = get_category(get_query_var('cat'));
$cat_name = $currCat -> name;
$cat_id = get_cat_ID($cat_name);
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$wp_query = new WP_Query(array(
'post_type' => 'post','post_status' => 'publish','posts_per_page' => 6,'cat' => $cat_id,'paged' => $paged));
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),'format' => '/page/%#%','current' => max(1,$paged),'prev_text' => __('PrevIoUs Page'),'next_text' => __('Next Page'),'show_all' => true,'total' => $query->max_num_pages ));?>
<div id="primary" class="content-area container">
<div id="content" class="site-content" role="main">
<div class="post-category">
<h2 class="post-category-title"><span class="post-category-title-m"><?PHP single_cat_title();?></span></h2>
</div>
<div class="post-items">
<?PHP if ($wp_query-> have_posts() ) : ?>
<?PHP while ($wp_query -> have_posts() ) : $wp_query -> the_post(); ?>
<div class="post-item">
<div class="post-thumbnail"><?PHP the_post_thumbnail('single-thumbnail'); ?></div>
<div class="post-title"><a href="<?PHP the_permalink(); ?>"><?PHP the_title(); ?></a></div>
<strong>
<?PHP the_date( 'F j,Y','<div class="post-date">','</div>'); ?>
<div class="post-excerpt"><?PHP the_excerpt();?></div>
</strong>
</div>
<?PHP endwhile;
else :
// No Post Found
endif; ?>
</div>
<nav class="page_nav">
<?PHP custom_pre_get_posts($wp_query); ?>
</nav>
<!-- <?PHP //wp_reset_postdata(); ?> -->
</div>
</div>
<?PHP get_footer();?>
function custom_pre_get_posts($query)
{ global $paged;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big,'format' => '?paged=%#%','total' => $query -> max_num_pages
));
if ($query->is_main_query() && !$query->is_Feed() && !is_admin() && is_category()) {
$query->set('page_val',get_query_var('paged'));
$query->set('paged',0);
}
}
add_action('pre_get_posts','custom_pre_get_posts');
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)