我正在尝试从显示分页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新手,所以请有人帮我:)。