• Resolved Craig Jamieson

    (@digiguru)


    Hi

    I have done several tutorials and followed many hacks and sometimes for a while it works and mostly it doesn’t work so I end up starting again. My list pages pagination don’t work when I go to the second page of list items. I get an error 404.

    My custom work.php page looks like this

    <?php 
    
    /*
    
    	Template Name: Work Page
    
    */
    
    get_header(); ?>
    
    <div id="content" class="clearfix">
    
    <?php
    
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array( 'post_type' => 'work', 'paged'=> $paged ); $the_query = new WP_Query( $args ); ?>
    
    <h1><?php the_title(); ?></h1>
    
    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    <section class="post-content clearfix">
    <h4><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    </section>
    					    <?php endwhile; ?>
    
    						        <nav class="wp-prev-next">
    							        <ul>
    					        	        <li class="prev-link left"><?php next_posts_link( 'Older Work', $the_query->max_num_pages ); ?></li>
    					        	        <li class="next-link right"><?php previous_posts_link( 'Newer Work' ); ?></li>
    							        </ul>
    					    	    </nav>
    
    					    <?php else : ?>
    
    	<p>There are no posts or pages here</p>
    
    <?php endif; ?>
    </div>
    
    <?php get_footer(); ?>

    The page is http://craigjamieson.com/work and it’s when you use the pagination below that it breaks when going to the next 10 posts.

    Please advise, I have followed so many hacks and they keep breaking and I’m simply getting confused.

    Thanks in advance 🙂

    https://wordpress.org/plugins/custom-post-type-ui/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Yeah, I know how you feel with this topic. Getting pagination to work with custom post types and custom loops can definitely be a pain. It’s also an issue that stems from WordPress core, as opposed to our plugin.

    That said, is there any reason why you couldn’t use the generated archive for the post type, at least when you have it set to create archives. That may be a better route to go, and it’d solve the pagination issue since the original $wp_query would be based on the post type.

    Thread Starter Craig Jamieson

    (@digiguru)

    Hi Michael

    Thanks for the response. I thought I’d give your suggestion a try and went and set the archive to be true, but I don’t see how it works. I updated my functions file, but when I test, I don;t see any changes. I assume I’m doing something wrong. Is there some sort of tutorial I could follow?

    Thanks

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    When going the archives route, you’ll have a url like http://www.mydomain.com/post-type-slug with “post-type-slug” being the actual slug you provided. I believe the archive will be interpreted before the page version, so it should kick in pretty quick.

    Archives will rely on archive.php if you don’t have something more specific like archive-post-type-slug.php, and if you don’t have archive.php, it’ll go to index.php, if I recall my hierarchy correctly.

    This method overall would eliminate the need to use a page to display the paginated archive.

    Hopefully this is making sense

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘List page posts error’ is closed to new replies.