Gabriel Gray
Gabriel Gray

Reputation: 63

Trying to implement pagination for a specific category ( WORDPRESS )

I implemented a custom post type for a discography. I managed to edit my template's loop, so it shows all the posts with the "Track" type, but now the pagination is not working anymore.

This is the code in the loop :

<?php
$args = array( 'post_type' => 'Track', 'posts_per_page' => 5);
     $loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();
?>

//HERE COMES MY HTML STUFF


<?php    endwhile;?>
<?php fuse_pagenavi(); ?>

And this is the code for my fuse_pagenavi() :

<?php
function fuse_pagenavi($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 class=\"pageof\">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 class=\"pageof\" href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a class=\"pageof\" href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>\n";
     }
}
?>

Thank you in advance !

UPDATE :

Ok I think I make some progress. I installed the wp-pagenavi plugin and now i see the pagination links at the bottom of the page but they point to mysite.com/?paged=x instead of pointing to mysite.com/?page=x.... i tested manually with 'page' and it works...

The code is the following :

<?php
$paged = get_query_var('page');
$my_query = new WP_Query($args);

$args = array( 'post_type' => 'Track', 'posts_per_page' => 5,'paged' => $paged);
         $loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>

//HTML STUFF


<?php 
wp_pagenavi(array('query' => $loop));
wp_reset_postdata();
 ?>

How can I make my pagination links to point to mysite.com?page=x instead of paged=x. Thanks

Upvotes: 0

Views: 434

Answers (2)

Adib Aroui
Adib Aroui

Reputation: 5067

Are you using loop inside of loop. If so, I think this : https://wordpress.stackexchange.com/questions/89191/using-query-posts-inside-single-php-loop is useful for you.

Good luck

Upvotes: 0

mehedi doha
mehedi doha

Reputation: 139

try this:

<?php
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$args = array( 'post_type' => 'Track', 'posts_per_page' => 5, 'paged' => $paged);
  $loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();
?>

//HERE COMES MY HTML STUFF


<?php    endwhile;?>
<?php fuse_pagenavi(); ?>

Upvotes: 1

Related Questions