• kieranmcclung

    (@kieranmcclung)


    I’ve got a pagination function here, modified slightly from the original, but I was wondering how I would go about only showing two pages of pagination?

    function pop_pagination($pages = '', $range = 2) {
    	$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 "<ul id='pagination'>";
    		if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo;</a></li>";
    		if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a></li>";
    
    		for ($i=1; $i <= $pages; $i++)
    		{
    			if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
    			{
    				echo ($paged == $i)? "<li class='active'>".$i."</li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
    			}
    		}
    
    		if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a></li>";
    		if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>&raquo;</a></li>";
    		echo "</ul>\n";
    	}
    }

    My query args are as follows:

    $args = array(
          'cat' => 2,
          'posts_per_page' => 6,
          'paged' => $paged,
          'orderby' => 'date',
          'order' => 'DESC'
          );
        query_posts( $args );

    Is there a way to query 6 posts per page with a total of 12 posts?

    Thank you.

Viewing 1 replies (of 1 total)
  • Thread Starter kieranmcclung

    (@kieranmcclung)

    if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
    			{
                                    if($i <= 2) {
    				        echo ($paged == $i)? "<li class='active'>".$i."</li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
                                    }
    			}

    I’ve just made this adjustment and it appears to work, not sure whether there are any implications or not but if not it could be useful for someone.

Viewing 1 replies (of 1 total)
  • The topic ‘Limit number of pages in pagination’ is closed to new replies.