I am wanting to display the number order of a post. I tried using<?php the_ID(); ?>
but this just displays the post ID and doesn’t seem to do go in sequential order due to post revisions and whatnot.
Is there a way to to display if the post is #2 or #3 or #4 and so on?
Thanks!
Post ID’s aren’t meant to be sequential. To number your posts sequentially, you’d have to use a meta field. There was discussion of this while back on this question:
Change Permalinks Structure to a Sequential Number for Each Post?
And the best answer for what you’re looking to do seemed to be a snippet of code posted on the support forums:
http://wordpress.org/support/topic/display-sequential-post-numbercount-not-post-id
(I modified it very slightly to sort by post date, rather than just ID as the initial code did.)
It will hook into all post actions (save/publish/delete) and update the ‘incr_number’ custom field for all posts. So you’ll have a performance lag on saving posts when you have a large number in the database, but once the posts are saved, showing the number is as simple as
If you don’t want to save the sequential post number in custom field and update it on every post action you can get all posts as an array of wordpress IDs and then search this array to get the single post number.
I use get_posts to retrieve all IDs and I order posts ascending by date, so the oldest of all posts will always be first in the array: