请容忍我。。
管理区域中每页的默认帖子数为10。在一些测试期间,我想将自定义帖子存档的每页帖子数更改为2(在WP 3.1中)。
问题是我只有4篇帖子,所以应该有2个页面,每个页面上有2篇帖子,但由于默认值为10,转到/page/2返回错误404(假设因为每页有10篇帖子,所以不会有第二页)
解决这个问题的唯一方法是将管理区域中的默认值设置为1,但这并不是很理想,因为我现在必须为所有帖子类型的存档执行自定义query\\u post来设置每页的帖子。
有没有人有更好的方法来做到这一点,或者有什么想法?谢谢
存档项目。php:
<?php get_header(); ?>
<?php
global $wp_query;
query_posts(array_merge($wp_query->query, array(
\'paged\' => get_query_var(\'paged\'),
\'posts_per_page\' => 2
)));
?>
<h1 class="title"><?php _e(\'Previous work\', \'fullycharged\'); ?></h1>
<?php if (have_posts()): while(have_posts()): the_post();?>
<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>" <?php post_class(\'launch col col-\' . $i); ?>>
<span class="project-title"><?php the_title(); ?></span>
<?php the_content(); ?>
</a>
<?php endwhile; endif; ?>
<?php if ($wp_query->max_num_pages > 1): ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( \'<span class="meta-nav">←</span> Older posts\', \'twentyten\' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( \'Newer posts <span class="meta-nav">→</span>\', \'twentyten\' ) ); ?></div>
</div>
<?php endif; ?>
<?php get_footer(); ?>
注册职位类型:
register_post_type(\'project\', array(
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'labels\' => array(
\'name\' => __(\'Projects\', \'fullycharged\'),
\'singular_name\' => __(\'Project\', \'fullycharged\'),
\'all_items\' => __(\'All Projects\', \'fullycharged\'),
\'add_new_item\' => __(\'Add New Project\', \'fullycharged\'),
\'edit_item\' => __(\'Edit Project\', \'fullycharged\'),
\'update_item\' => __(\'Update Project\', \'fullycharged\')
),
\'menu_icon\' => get_stylesheet_directory_uri() . \'/images/monitor-off.png\',
\'menu_position\' => 5,
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'rewrite\' => array(\'slug\' => \'work\', \'with_front\' => false),
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'custom-fields\')
));