【发布时间】:2011-03-03 12:29:27
【问题描述】:
我也有类似的问题 (https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination),不知道该怎么办!
我有一个自定义帖子类型名称“画廊”,并且我创建了一个模板来显示所有“画廊”项目。网址是 www.domain.com/gallery。我使用 WP_Pagenavi 插件。每当我尝试转到第 2 页或更高页面时,url 变为 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( );
?>
这是我的库的functions.php代码
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)拉我的头发。 提前谢谢你!
【问题讨论】:
标签: wordpress