Trying to count posts UP TO a particular post ID
-
I am trying to define a number, to control a jcarousel instance, so that when a single page loads, it will figure out where to load the jcarousel menu and load up set it to start there…
the navigation in the grey box on this (or any single) page is what I’m aiming to control… anyhow…
I’m invoking a custom loop, setting the count to zero, then attempting to increment that number, until the loop comes up to the current $post->ID. Then it should stop and be able to echo out that number. I’ll probably have to do some sort of expression to the number, to get the jcarousel instance to load up on the proper page… but if I can get something other than zero, then perhaps I’ve got a chance.
<?php $currentPost = $post->ID; // set current post ID //OK? $currentCat = get_query_var('cat');// get the query variable for the current category//OK? $arguments = array( 'category__in' => array($currentCat), //set category parameter//OK? 'showposts' => -1, //retrieve all posts (in the above category)//OK? ); ?> <?php $pageCount_query = new WP_Query($arguments); while ($pageCount_query->have_posts()) : $pageCount_query->the_post(); global $pageCount_query; $pageCount_query->in_the_loop = true; // This line is added so that the_tags('') will work outside the regular loop. static $positionCount = 0; if( $post->ID == $currentPost ) { break; } // if the current post ID in the loop, is the post ID, then stop the loop else { ?> <?php $positionCount++; } ?> <?php endwhile; ?> <?php //endif: ?> <?php echo $positionCount; ?> <?php if ($positionCount < 5) { // positionCount is less than 5, start on page one echo 'start: 1'; } elseif ($positionCount >= 5) { // positionCount is 5, or less than 8, start on page two echo 'start: 2'; // if position count is 1 - 4, start on page 1 // if position count is 5 - 8, start on page 2 // if position count is 9 - 12, start on page 3 // if position count is 13 - 16, start on page 4 // and so on }?>
- The topic ‘Trying to count posts UP TO a particular post ID’ is closed to new replies.