我有类似的问题(https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination),并不能真正弄清楚该怎么做!Pagenavi插件和自定义帖子类型导航错误(404)
我有一个自定义的帖子类型名称'画廊',我创建了一个模板来显示所有'画廊'项目。该网址是www.domain.com/gallery。我使用WP_Pagenavi插件。每当我尝试转到第2页或更高版本时,网址将变为www.domain.com/gallery/page/2,并且它会返回404页面。我到处阅读,我想这与重写规则,查询和其他任何事情有关!
我曾尝试加入
add_rewrite_rule('gallery/page/([0-9]+)/?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top');
的事情是,我不想改变我的永久链接结构,也就是现在的/%postname%/。
这里是我完整的代码
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'gallery',
'paged' => $paged,
'showposts' =>24
); query_posts($args);
if (have_posts()) : while (have_posts()) : the_post(); ?>
...stuff here...
<?php endwhile; endif; ?>
<?php
wp_pagenavi();
?>
,这里是我的画廊
add_action('init', gallery);
function gallery() {
$args = array(
'label' => __('Gallery'),
'singular_label' => __(Gallery),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')
);
register_post_type('gallery' , $args);
add_rewrite_rule('gallery/page/([0-9]+)/?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top');
}
我拉我的头发与此(grrrrr)的functions.php代码。 提前谢谢!
Thanx!这是关于刷新永久链接结构 – Pantso 2011-03-08 07:40:57
是啊任何时候你添加一个新的分类或CPT你需要刷新规则访问页面并点击保存(真的只是访问页面应该这样做) – curtismchale 2011-03-08 23:51:29