Bear with me here..
The default posts per page in the admin area is 10. During some testing I wanted to change the posts per page for my custom post archive to 2 (in WP 3.1).
The problem is that I only have 4 posts, so there should be 2 pages with 2 posts on each, but because the default is at 10, going to /page/2 returns error-404 (assuming because with 10 posts per page there wouldn't be a second page)
The only way to get around this was to set the default in the admin area to 1, but it's not really ideal as i now have to do a custom query_post for all post type archives to set the posts per page.
Does anyone have a better way to do this, or any ideas? Thanks.
archive-project.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:
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')
));
get_query_var( 'page' );
?global $paged;
query_posts(array_merge($wp_query->query, array(
` 'paged' => $paged,` ` 'posts_per_page' => 2`)));
Thats all the changes to the query i've made, noget_query_var( 'page' );
, but i've used the$paged
global because archive pagination uses $paged rather than $page Sorry for the bad formatting'rewrite' => 'recipes
' ? If so you're confusing wordpress with your links/recipes
, just registered the custom post in thefunctions.php
file. I'm able to get the first page of my recipes archive at/recipes
, but when I change the posts_per_page in thearchive-recipes.php
file to something other than the value inWP-Admin -> Settings -> Reading
will result in a "page 'n' shouldnt exist (when it really should, according to my altered posts_per_page)" error. I dont think its my code inarchive-recipes.php
because placingexit;
at the top of the file doesn't do anything/recipes
shows the first page of the archive,/recipes/page/2
doesn't reach thearchive-recipes.php
template file because page 2 shouldn't exist, based on the settings inWP-Admin -> Settings -> Reading