WP – Pagination in category loop not working

I have problem with pagination in my loop in category.php

Link send me to: ?cat=9&paged=2 don’t show posts just home page.

My loop:

$temp = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query(); 
$wp_query->query('showposts=2&post_type=blog'.'&paged='.$paged); 

while ($wp_query->have_posts()) : $wp_query->the_post(); 

    //CONTENT

endwhile;
get_template_part('pagination'); 
$wp_query = null; 
$wp_query = $temp;  // Reset

and this is function:

function silon_pagination($pages = '', $range = 4){  
    $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>Strona ".$paged." z ".$pages."</span>";
        if($paged > 2 && $paged > $range+1 && $showitems < $pages) 
            echo "<a href='".get_pagenum_link(1)."'>&laquo; Pierwsza</a>";
        if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Poprzednia</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)."">Następna &rsaquo;</a>";  
        if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages)
            echo "<a href='".get_pagenum_link($pages)."'>Ostatnia &raquo;</a>";

         echo "</div>n";
     }
}

function is from here:
http://design.sparklette.net/teaches/how-to-add-wordpress-pagination-without-a-plugin

Please help 🙂

Read more here: WP – Pagination in category loop not working

Leave a Reply

Your email address will not be published. Required fields are marked *