Custom post archive and pagination not working
-
For reasons I won’t go in details into, I have had to create custom posts for our website and now I am having trouble getting the pagination to work on the archives pages for each new post type.
I can have the page display only the first 6 (number I chose) items, but clicking on “Next” leads me to a “Page not found” page.
Here’s how I created the new post types:
function createPostType( $slug, $singularSlug, $name, $singular, $allowComments = true ) { register_post_type( $slug, array( 'labels' => array( 'name' => __( $name ), 'singular_name' => __( $singular ), 'menu_name' => __( $slug ) ), 'public' => true, 'has_archive' => true, "show_in_menu" => true, "show_in_nav_menus" => true, "taxonomies" => array("category"), "supports" => array( "title", "editor", "author", "thumbnail", "excerpt" ) ) ); if( $allowComments ) add_post_type_support( $slug, array( 'comments' ) ); } function createNewPostTypes() { createPostType( "themes", "theme", "Thèmes", "Thème", false ); createPostType( "articles", "article", "Articles", "Article" ); createPostType( "galleries", "gallerie", "Galeries", "Galeries" ); createPostType( "videos", "video", "Vidéos", "Vidéo" ); }
and this is the archive’s template:
<?php get_header(); ?> <div id="primary" class="site-content dual-column-layout"> <div id="content" role="main"> <?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $wp_query->query('showposts=6&post_type=articles'.'&paged='.$paged); $counter = 0; while ($wp_query->have_posts()) : $wp_query->the_post(); if( $counter == 0 ) echo "<div style='clear: both'>"; echo "<a href='".get_permalink()."'>"; echo "<div class=\"post-list-thumbnail\">"; generateThumbnail( ThemeThumbnailRenderer ); echo "</div>"; echo "</a>"; $counter++; if( $counter == 2 ) { echo "</div>"; $counter = 0; } if( ( $wp_query->current_post + 1 ) == ( $wp_query->post_count ) && $counter != 0 ) echo "</div>"; endwhile; ?> <nav> <?php previous_posts_link('« Newer') ?> <?php next_posts_link('Older »') ?> </nav> <?php $wp_query = null; $wp_query = $temp; // Reset ?> </div> </div> <?php get_sidebar(); get_footer(); ?>
I have tried the many solutions given by people on this forum, but nothing seems to work. I thought it might have been the URL rewrite problem, but it wasn’t (prior to the current configuration I’m using, I was using the Article Name options for URLs. I now reverted to default). Or at least it does not seem like it is.
I am starting to wonder if a working pagination is something possible for custom post’s archives…
- The topic ‘Custom post archive and pagination not working’ is closed to new replies.