Grow your CSS skills. Land your dream job.

Numbering WordPress Posts

  • # October 31, 2013 at 9:30 am

    Does anyone know how to number WordPress posts?

    I don’t mean using an ordered list or adding counter to the loop. I mean the first published post is numbered 1, and the 134th post is numbered 134, so no matter how it’s displayed it’ll always have that number associated with it.

    I could just add a custom meta box and number it with that, but I’m looking for a way to do it dynamically.

    Thanks

    # October 31, 2013 at 10:02 am

    Does it really have to start at 1 and can’t skip anything? (what if you have 10 posts numbered 1-10 and number 7 is deleted…does the numbering of posts 8-9-10 adjust to that or will number 7 just not exist anymore? etc.)

    If you don’t care about that, then obviously you could just use the post ID as the unique number.

    # October 31, 2013 at 10:16 am

    A deleted post isn’t an issue. I can deal with gaps like that, but the problem with using post_ID() is other post types and plugins that use post types will add to the number. I want to keep the count for lets say just articles, excluding other post types from that count. It could be like one post is number 20 and the next is 122 if there were posts from other post types made.

    I’m thinking I could make a readonly meta box that queries the posts, count the number of post with a loop, and then add 1 to the meta field, but I’m worried that there might be performance issues if the posts get into the hundreds.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".