Support » Fixing WordPress » Increment, continuous post ID

  • Hi all, I need to add an increment, continuous post ID to every post other than WordPress default post_ID, so do a search and found this post is useful:

    With the code <div id="post<?php echo($wp_query->current_post + 1); ?>"> I could get IDs like 1, 2, 3, 4, 5. but the next page (/page/2/) the ID of the first post reset to 1, I expect the number could be 6, 7, 8, 9 and 10. does anyone know how to make the ID continuous even in next page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • maybe this can help:
    also read through the comments for how to reverse the numbering with the latest post starting with number 1

    Thanks a lot, but this only works in normal post query. I mean, if it’s in a posts list of specified tag or category, the numbers are still messed up.

    As apposed to going through the Post ID’s, why don’t you collect all the posts in an array, then go through the array? Or does it require a query, thus requiring the actual ID stored in the database?

    If not…

    Reference this:

    I had trouble doing it without messing up the original loop (although there are better fixes)
    Here’s mine:

    $newposts = get_posts('numberposts=-1&category=1');
     	//get all posts (no limit) in new category (look up function in codex for full explination
    $maxnew = count($newposts);	// count # posts in array
    for($q=0;$q<$maxnew;$q++){    // Loop through posts array
    	$newpostsid[$q] = $newposts[$q]->ID;
                              // assign post ID's to new array
    	echo $newpostsid[$q] . " ";
    //Just double check that it increments all the way through, the # of posts there are.

    $newpostsid[$q] will be the current post for each loop.

    Good luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Increment, continuous post ID’ is closed to new replies.