• I have a problem whereby I have a page containing custom post types and the second page does not show the rest of the posts.

    to expand a little further, I have 12 thumbnails on each page and the first 12 thumbnails are showing up in the second page instead of the second set of 12 thumbnails, if this makes sense?

    Anyone know how to fix this problem, would be greatly appreciated.

    Here’s my code to pull in the custom post types and the pagination.

    <div class="postnm">
         <?php
         query_posts( array( 'post_type' => 'portfolio',  'orderby' => 'menu_order', 'order' => 'ASC') );
    	 ?>
    
            <?php if(have_posts()) : ?>
    		<?php while(have_posts()) : the_post();
    		$c++;
    if( $c == 3) {
    	$style = 'post-mvg nm one_third last';
    	$c = 0;
    }
    else $style='post-mvg one_third';
    		?>
    
                <div <?php post_class($style) ?>>
                <div class="portimg"><a href="<?php the_permalink(); ?>"><img src="<?php echo get_field('company_logo') ?>"/></a></div>
              <!--<div class="small"><a href="</?php the_permalink(); ?>"></div>?php the_title(); ?></a></div>-->
    
                </div>
                 <?php endwhile; ?>
                  <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('&laquo; show previous images') ?></div>
      <div class="alignright"><?php next_posts_link('Show more images &raquo;') ?></div></div>
                <?php endif; ?>
    
     <!-- Loop -->
     <?php $c=0; ?>
    
    </div>
Viewing 1 replies (of 1 total)
  • Thread Starter Jimladen

    (@jimladen)

    Found a solution.

    This may only work for twenty-eleven theme.

    First step:

    Add this 'paged' => get_query_var('paged') to the post query

    <?php
    	  global $query_string; query_posts($query_string . '&posts_per_page=10');
         query_posts( array( 'post_type' => 'portfolio',  'orderby' => 'menu_order', 'order' => 'ASC', 'paged' => get_query_var('paged')) );
    	 ?>

    Second Step

    Add this after the posts loop

    <div class="navigation">
    <?php jimladen_pagination(); ?>
    </div>

    Third Step

    Add this to functions.php

    function jimladen_pagination($pages = '', $range = 3) {   /* handle pagination for post pages*/
        $showitems = ($range * 2)+1;  
    
        global $paged;
        if(empty($paged)) $paged = 1;
    
            if($pages == '')
            {
                global $wp_query;
                $pages = $wp_query->max_num_pages;
                if(!$pages)
                {
                $pages = 1;
                }
            }   
    
            if(1 != $pages)
            {
                echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
                if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
                if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
    
                for ($i=1; $i <= $pages; $i++)
                {
                    if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                    {
                         echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
                    }
                }
    
                if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
                if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
                echo "</div>\n";
            }
        } //  jimladen_pagination

    Hope I have helped to save somebodys patience with this.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type page navigation / pagination not working’ is closed to new replies.