• Resolved michaeloc

    (@michaeloc)


    Hello I am trying to add pagination to a page template which I am using to display a custom post type. I have looked around for a few hours but I haven’t come across clear set of instructions to follow.

    Below is all the code from my page template php file. If someone could point me in the right direction it would be much appreciated.

    I would appreciate any help on how to add the code for

    <?php
    /**
     * Template Name: Testimonials Template
     *
     * This is the template for testimonials page.
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    get_header(); ?>
    
    <?php include("2011-header-image.php"); ?>
    
    		<div id="primary">
    
    <?php get_sidebar(); ?>
    
    			<div id="content" role="main">
    
    			<?php include("kinlay-breadcrumb.php"); ?>
    
    				<hgroup>
    					<h1 class="entry-title"><?php the_title(); ?></h1>
    				</hgroup>
    
    			<?php query_posts(array('post_type'=>'testimonials')); ?>
    
    				<?php while ( have_posts() ) : the_post(); ?>
    
    <?php 	// The code must be inserted ahead of the call to the content
    global $more;
    $more = 0;
    ?>
    
    					<?php get_template_part( 'content', 'testimonials' ); ?>
    
    					<?php // comments_template( '', true ); ?>
    
    				<?php endwhile; // end of the loop. ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Try changing this:

    <?php query_posts(array('post_type'=>'testimonials')); ?>

    to this:

    <?php
    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    query_posts(array('post_type'=>'testimonials', 'paged' => $paged));
    ?>

    And, insert this:

    <div class="navigation">
       <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
       <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    just after the end of the loop.

    You may need to add or change some CSS to get the alignment right.

    Thread Starter michaeloc

    (@michaeloc)

    Thanks vtxyzzy,

    I ended up installing the page navi plugin

    and inserting code below and it’s now working. I like your solution because it doesn’t require a plugin so will keep for future reference

    <?php
      $paged = get_query_var('paged') ? get_query_var('paged') : 1;
      $wp_query = new WP_Query(array('post_type' => 'testimonials',
                                     'paged' => $paged,
                                     'post_per_page' => 5)
                               );
      while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pagination for custom post type on page template’ is closed to new replies.