WordPress遇到分页问题

时间:2013-10-04 作者:Rajnikanth

我正在尝试从显示分页archive.php 使用我的自定义帖子类型news 但当我点击下一页时404 page

My Custom Post Type Code:

function codex_custom_init() {
  $labels = array(
    \'name\'               => \'News\',
    \'singular_name\'      => \'News\',
    \'add_new\'            => \'Add News\',
    \'add_new_item\'       => \'Add New News\',
    \'edit_item\'          => \'Edit News\',
    \'new_item\'           => \'New News\',
    \'all_items\'          => \'All News\',
    \'view_item\'          => \'View News\',
    \'search_items\'       => \'Search News\',
    \'not_found\'          => \'No news found\',
    \'not_found_in_trash\' => \'No news found in Trash\',
    \'parent_item_colon\'  => \'\',
    \'menu_name\'          => \'1. News\'
  );

  $args = array(
    \'labels\'             => $labels,
    \'public\'             => true,
    \'publicly_queryable\' => true,
    \'show_ui\'            => true,
    \'show_in_menu\'       => true,
    \'query_var\'          => true,
    \'rewrite\'            => array( \'slug\' => \'news\' ),
    \'capability_type\'    => \'post\',
    \'has_archive\'        => true,
    \'hierarchical\'       => false,
    \'menu_position\'      => null,
    \'supports\'           => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
  );

  register_post_type( \'news\', $args );
}
add_action( \'init\', \'codex_custom_init\' );
以及My Pagination Code:

<?php 
    // the query to set the posts per page to 3
    $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
    $args = array(\'posts_per_page\' => 2, \'post_type\' => \'news\' , \'paged\' => $paged );
    query_posts($args); 
?>
<!-- the loop -->
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
    <div class="news-main">
        <div class="news-image"><img src="<?php echo get_field(\'image\'); ?>" /></div>
        <div class="news-container">
            <h1><?php echo the_title(); ?></h1>
            <p><?php echo the_content(); ?></p>
        </div>
    </div>
<?php endwhile; ?>
<!-- pagination -->
    <?php next_posts_link(); ?>
    <?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>
我是WordPress新手,所以请有人帮我:)。

1 个回复
最合适的回答,由SO网友:P-S 整理而成

你的代码对我来说很好,也许你需要通过访问Settings->Permalinks 仪表板上的屏幕。

注意:访问Permalinks屏幕会触发重写规则刷新。不需要仅为了刷新重写规则而保存。

http://codex.wordpress.org/Settings_Permalinks_Screen#Customize_Permalink_Structure

结束

相关推荐

Pagination and multiple loops

对,所以我现在有一个使用css网格将页面分成三部分的页面。第三列是侧栏,前两列各有一个要显示的帖子查询,并创建一个漂亮的帖子网格(虚拟内容):http://puu.sh/2Xh9o.jpg每个循环如下所示: <?php query_posts(\'showposts=5\'); ?> <?php $posts = get_posts(\'numberposts=5&offset=0\'); foreach ($posts as $post) : start_wp()