Title: Custom Pagination count
Last modified: August 19, 2016

---

# Custom Pagination count

 *  [Quincy](https://wordpress.org/support/users/lodjixmedia/)
 * (@lodjixmedia)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-pagination-count/)
 * Hi,
 * I am trying to create a counter (starts at 0), that will count all posts queried
   and apply the # from the counter to each post’s link (appends ?pk=counter to 
   the end of the_permalink(); url.
 * What happens next is that this parameter is retrieved in the single post page,
   where it’s used to determine what image to display first in jquery cycle list
   of images.
 * The page in question is: [http://dm.lodjixmedia.net/portfolio/](http://dm.lodjixmedia.net/portfolio/)
 * If you click on any one of the first 9 posts on that page, it displays the correct
   image on the single.php page.
 * The problem is that when you use WP pagination, any new page will reset the counter
   to 0. So if I am displaying 9 posts per page, the first page should count from
   0 to 8 (this works fine), but page 2 should continue from 9… and so on. I’ve 
   managed to make this work fine if I query only one category, and is able to keep
   the count correct on other paginated pages with the following code:
 *     ```
       //detect the set number of posts per page
       $ppp = get_option('posts_per_page');
   
       // first page 9 posts
       if (!is_paged()) {
           $img_counter = $img_counter + 0;
       // second page with offset
       } elseif($paged == 2) {
           $img_counter = $img_counter + 9;
       // all other pages with settings from backend
       } else {
           $img_counter = $img_counter + (9*($paged-1));
       }
       ```
   
 * And inside the loop, where the link is applied, I append the value as follows:
 * `<?php the_permalink(); ?>?pk=<?php echo $img_counter; ?>`
 * On Single.php, I retrieve the parameter “pk”
 * `$pos = $_GET['pk'];`
 * and apply it to my JQuery cycle list as follows:
 *     ```
       $(function(){
       	$('#main_slides')
       	.cycle({
       		fx:     'scrollHorz',
       		speed:  'slow',
       		easing: 'easein',
       		timeout: 0,
       		prev:'#prev',
                       next:'#next',
                       startingSlide: <?php echo $pos; ?>,
       		pause:   1
       	});
       });
       ```
   
 * The problem I’m having is that I am querying multiple categories (3 to be exact).
 *     ```
       $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=5,6,7&paged=$page&orderby=date&order=DESC&posts_per_page=9");
       while(have_posts()) : the_post();
       ```
   
 * With this method, while displaying “all” posts on the portfolio page ([http://dm.lodjixmedia.net/portfolio/](http://dm.lodjixmedia.net/portfolio/)),
   the count always increases. However, on single.php, the images displayed are 
   all listed from the category of the image you selected in the portfolio. So if
   each of the 3 categories has 15 posts, then the last item on the last paginated
   page will be 44 (starting value is 0).
 * The single.php page will only list posts in a category at a time (this is what
   I intended), and therefore will only list 15 images (from the 15 posts for that
   category). The value of the parameter passed is then used to determine the starting
   position of the slides in the cycle of images displayed.
 * I’d like to know how can I create a counter that keeps counting across the paginated
   pages, but will have a different count per category. So it will only count within
   it’s own category although I am querying 3 categories at a time. This way, the
   parameter passed will always be associated with the correct slide on single.php.
 * I apologize for the long post, this is my first post and I wanted to explain 
   my issue clearly. I appreciate any help or suggestions as I’m still fairly new
   to WP.
 * Thanks guy (let me know if you’d like me to add any more code to help clarify
   this).
 * Cheers

Viewing 1 replies (of 1 total)

 *  Thread Starter [Quincy](https://wordpress.org/support/users/lodjixmedia/)
 * (@lodjixmedia)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-pagination-count/#post-1580510)
 * Hi,
 * If anyone would like me to provide more information to clarify this issue, please
   advise. I’d appreciate any suggestions or thoughts from one of the wordpress/
   php guru’s on this site…
 * Thank you =)

Viewing 1 replies (of 1 total)

The topic ‘Custom Pagination count’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Quincy](https://wordpress.org/support/users/lodjixmedia/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/custom-pagination-count/#post-1580510)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
