Advertisement
Guest User

Untitled

a guest
May 30th, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.69 KB | None | 0 0
  1. // Placed in functions.php
  2. <?php
  3.  
  4. function Get_Post_Number($postID){
  5.     $temp_query = $wp_query;
  6.     $postNumberQuery = new WP_Query('orderby=date&order=ASC&category_name=episodes&posts_per_page=-1');
  7.     $counter = 1;
  8.     $postCount = 0;
  9.     if($postNumberQuery->have_posts()) :
  10.         while ($postNumberQuery->have_posts()) : $postNumberQuery->the_post();
  11.             if ($postID == get_the_ID()){
  12.                 $postCount = $counter;
  13.             } else {
  14.                 $counter++;
  15.             }
  16.     endwhile; endif;
  17.     wp_reset_query();
  18.     $wp_query = $temp_query;
  19.     return $postCount;
  20. }
  21.  
  22. ?>
  23.  
  24. //Used to call function in template
  25. <?php $currentID = get_the_ID(); ?>
  26. <?php $currentNumber = Get_Post_Number($currentID); ?>
  27.  
  28. <?php echo $currentNumber; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement