• Resolved Rachel Goldstein

    (@rachelgoldstein71)


    I am trying to get pagination to work on my custom post type archive, but when I click the link to the next page, the same 10 posts show up. I’ve been scouring the Internet for solutions, but don’t know how to integrate them with my particular code.

    <?php if(is_single()){ ?>
    		<?php while ( have_posts() ) : the_post('orderby=menu_order&order=asc'); ?>
    			<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    			<div class="postContent"><?php the_content(); ?></div>
    		<?php endwhile; ?>
    	<?php }else { ?>
    		      <?php query_posts( 'post_type=projects' . '&orderby=menu_order&order=asc'); ?>
    			<?php while ( have_posts() ) : the_post('orderby=menu_order&order=asc'); ?>
    
    			<div class="postWrapper">
    			<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    			<?php
    					$args = array(
    							'order'          => 'ASC',
    							'orderby' 		 => 'menu_order',
    							'post_type'      => 'attachment',
    							'post_parent'    => $post->ID,
    							'post_mime_type' => 'image',
    							'post_status'    => null,
    							'size' => 'full',
    						);
    
    						$attachments = get_posts($args);
    						if ($attachments) {
    							foreach ($attachments as $attachment) {
    
    								?>
    
    								<a href="<?php the_permalink(); ?>">
    									<img src="<?php echo wp_get_attachment_url($attachment->ID); ?>" />
    								</a>
    							<?php }
    						}
    					?>
    			</div>
    			<?php endwhile; ?>
    <?php }; ?>
    
    	</div>
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?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">&larr;</span> Next page', 'twentyten' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Previous page <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
                    </div><!-- #nav-below -->
    <?php endif; ?>

    This was coded by a previous developer, I apologize in advance if it’s a bit sloppy.
    Thanks.

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Rachel Goldstein

    (@rachelgoldstein71)

    Actually, this problem arose because the projects got limited to 10 when we limited the posts to 10, necessitating the need for pagination. If we can change the limit to 20 for projects, then I don’t need the prev/next links. Which is easier?
    Thanks.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Changing it to 20 would be the easiest route, as I know that custom queries and pagination tend to be a big problem. I would also highly recommend against using query_posts() and instead creating a new query object for this using WP_Query class instead. Same argument parameters, bit different usage.

    Thread Starter Rachel Goldstein

    (@rachelgoldstein71)

    Changing custom post type “projects” to 20 is actually preferable to pagination- as long as I can keep the settings the same because we want to keep it to 10 for the posts. How can I change the post limit in the template?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    add &posts_per_page=20 to your query_posts()

    Thread Starter Rachel Goldstein

    (@rachelgoldstein71)

    Great – that worked. Thanks so much
    <?php query_posts( 'post_type=projects' . '&orderby=menu_order&order=asc' . '&posts_per_page=20'); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding pagination’ is closed to new replies.