WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type UI
Adding pagination (6 posts)

  1. RachelGoldstein71
    Member
    Posted 5 months ago #

    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/

  2. RachelGoldstein71
    Member
    Posted 5 months ago #

    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.

  3. Michael Beckwith
    Member
    Plugin Author

    Posted 5 months ago #

    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.

  4. RachelGoldstein71
    Member
    Posted 5 months ago #

    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?

  5. Michael Beckwith
    Member
    Plugin Author

    Posted 5 months ago #

    add &posts_per_page=20 to your query_posts()

  6. RachelGoldstein71
    Member
    Posted 5 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags