WordPress.org

Ready to get started?Download WordPress

Forums

Stuck on custom post type archives with pagination (4 posts)

  1. flint_and_tinder
    Member
    Posted 2 years ago #

    Hi all,

    I've tried many different ways to get pagination working on my custom post archives to no avail. Can anyone help please? Here's where I'm at:

    Post type is called 'Projects' and has the slug amended to videos:

    function projects_post_type() {
        register_post_type('projects', array(
            'labels' => array(
                'name' => 'Projects',
      			etc.
            ),
    		'has_archive' => true,
    		etc.
            ),
    		'rewrite' => array(
        		'slug' => 'videos'
      		),
            etc.

    I have created a specific archive-projects.pho with the following loop:

    <?php  query_posts( 'post_type=projects&showposts=8&paged='.$paged );
      if (have_posts()) : while (have_posts()) : the_post(); ?>
    post code etc.
             <?php endwhile; ?>
               </div>
                      <div id="nav-below" class="navigation">
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'vimeodrome' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'vimeodrome' ) ); ?></div>
                      </div><!-- #nav-below -->
      <?php endif; ?>

    The first page of the archive displays ok but when I click 'older posts' I get a 404 error on .../videos/page/2

    I've treid resetting my permalinks (which are currently set top custom > /%postname%/) but it still won't work. All tutorials I've found state the code I've used above should work, so what am I doing wrong?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try to set the $paged variable:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( 'post_type=projects&posts_per_page=8&paged='.$paged );
  3. flint_and_tinder
    Member
    Posted 2 years ago #

    Thanks Keesiemeijer but it still doesn't work with that code.

    I have managed to get it to work in a slightly different way though, which is to alter 'has_archive' to be 'false', then to add a template name to the archive-projects.php and finally create a standard page called Videos and set it to use the archive-project template. This allows me to add the link to the dashboard set menus as well which is a bonus.

    However, ideally I rather not have to rely on the user creating a page for the archive and that the custom post archives just worked 'out of the box'.

  4. flint_and_tinder
    Member
    Posted 2 years ago #

    Forgot to add that in the example above where I created a Videos page for the 'projects' to appear, that I had to delete the

    'rewrite' => array(
        		'slug' => 'videos'
      		),

    part of the functions code.

Topic Closed

This topic has been closed to new replies.

About this Topic