Numbering Posts

To give posts a continuous number in index pages or archives, try this little piece of code:

global $query_string;
  $all_post_query = new WP_Query($query_string.'&posts_per_page=-1');
    $count_posts = $all_post_query->post_count;
  $this_post_nr = 1 + $wp_query->current_post + (get_query_var('paged')?(get_query_var('paged')-1) : 0) * get_option('posts_per_page');
echo $this_post_nr.' of '.$count_posts.' in this selection of posts.';

Place it within the loop;
condition: needs to be adjusted for any custom query.

4 Replies to “Numbering Posts”

  1. Für den Anwendung eines Lammfellsattels gibt es keine geradlinigen Einschränkungen, daher ist er grundsätzlich für alle Pferderassen geeignet. Da es Lammfellsättel in divergentsten Modifikationn gibt, kann er gleichwohl reibungslos bei einem kleinen Pony eingesetzt werden. Es ist hingegen jedoch verheißungsvoll, die ungleichen Type der Hersteller miteinander zu kontrastieren. So bieten die Erzeuger Christ wie Eclipse einen angenähten D-Ring für die Aufhängung der Steigbügel an, während bei bspw. Grandeur die Steigbügel aufgeklettet werden.

  2. grin, maybe something less memory intensive might be better…
    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /xx/wp-includes/wp-db.php on line 1539 ….

    Maybe better to cache this count offline.

  3. Hi, this is exactly what I’m looking for, the problem is, in which file do I need to paste this code. I’m still learning wp, so it will be appreciated if you can help. I am working on a child theme as well for twenty eleven. Many thanks

    1. ‘Place it within the loop;’ – in a child theme of Twenty Eleven, this could be in content.php. where exactly depends on where you want to see the number. possibly directly after: <h1 class="entry-title">
      consider joining the support forum to ask any WordPress related questions.

Leave a Reply to alchymyth Cancel reply

Your email address will not be published. Required fields are marked *