S

Continued WordPress Post Numbering

June 13th, 2009

My further experimentation led me to requiring the current number of a post which there is surprisingly little information about, so I ended up working something out from scratch.

I’ve posted it on the wordpress forum in case it proves useful for anyone else: http://wordpress.org/support/topic/245629

Update: Since this is now closed, I have included the code I made originally here:


function Get_Post_Number($postID){
$temp_query = $wp_query;
$postNumberQuery = new WP_Query('orderby=date&posts_per_page=-1');
$counter = 1;
$postCount = 0;
if($postNumberQuery->have_posts()) :
while ($postNumberQuery->have_posts()) : $postNumberQuery->the_post();
if ($postID == get_the_ID()){
$postCount = $counter;
} else {
$counter++;
}
endwhile; endif;
wp_reset_query();
$wp_query = $temp_query;
return $postCount;
}

Posted in Web Design by Simon

If you enjoyed this journal entry you may also find the following entries interesting:

Add Comment Add a Comment

Latest Journal Posts

RSS Feed

Additional

Bad Behavior has blocked 15 access attempts in the last 7 days.