Pagination has until page 3 only wordpress

Can you take a look at this. Why is my pagination is only has 3 page even if I set it the $per_page to two it’s only showing up to page 3. Also if you don’t have content in that page it will show still. Please tell me what’s still missing.

Here is my current code.

Read More
<?php 
if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {$paged = 1;}

$per_page = 2;
$paged_offset = ($paged - 1) * $per_page;
$paginate = array(
    'orderby'           => 'name',
    'order'             => 'ASC',
    'hide_empty'        => 0,
    'number'            => $per_page,
    'paged'             => $paged,
    'exclude'           => array(1,5,15,18,14),
    'offset'            => $paged_offset
    );  

// get all the categories from the database
$cats = get_categories($paginate);
foreach ($cats as $cat) {
// setup the cateogory ID
    $cat_id= $cat->term_id;
    $cat_child =$cat -> category_parent;
// Make a header for the cateogry
    echo "<div class='anchor2' id='cat_".$cat_id. "'></div>";
    echo "<div id='". $cat_child ."'class='cat_id".$cat_id." cat-cont large-6 medium-6 columns pad25px'>";
    echo "<h5 class='title-post cat_id_" . $cat_id ."' >".$cat->name."</h5>";
    echo "<a href='".get_category_link($cat_id)."' class='see-more' target='_blank'>See more >></a>";
    $args = array(
        'cat' => $cat_id,
        'posts_per_page' => 5,
        );
    query_posts($args);
// start the wordpress loop!
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php get_template_part( 'parts/loop', 'archive-grid' ); ?>
<?php endwhile; ?>
<?php else : ?>             
    <?php get_template_part( 'parts/content', 'missing' ); ?>
<?php  endif; // done our wordpress loop. Will start again for each category ?>
<?php echo "</div>"; }// done the foreach statement 
?>

Here is the HTML

<ul class="pagination-link">
    <li class="alignleft">
        <?php
        if(!get_previous_posts_link()) {
            echo 'Prev <img src="' . get_bloginfo('template_url') . '/images/prev.png" width="30px"/>' ;
        } else {
            previous_posts_link('Prev <img src="' . get_bloginfo('template_url') . '/images/prev.png" width="30px"/>');
        }
        ?>
    </li>
    <li class="alignright">
        <?php
        if(!get_next_posts_link()) {
            echo ' <img src="' . get_bloginfo('template_url') . '/images/nxt.png" width="30px"/> Next' ;
        } else{
            next_posts_link('<img src="' . get_bloginfo('template_url') . '/images/nxt.png" width="30px"/> Next');
        }
        ?>
    </li>
</ul>

Related posts