Title: Post enumeration
Last modified: August 19, 2016

---

# Post enumeration

 *  [moarghorgh](https://wordpress.org/support/users/moarghorgh/)
 * (@moarghorgh)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/post-enumeration/)
 * Hey,
 * I would like to enumerate my posts starting by 1.
 * I don’t want to write every number manually in every post but I’m not sure how
   to automate the process.
 * Here’s my code – ENTRY NUMBER is the place where the dynamic number sould go.
 *     ```
       <?php while ( have_posts() ) : the_post() ?>	
   
       	<div class="col1">
   
       		<div id="post-<?php the_ID(); ?>" class="entry">
   
       			<h2 class="entry-title">ENTRY NUMBER <?php the_title() ?></h2>
   
       			<div class="entry-content"><?php the_content('(...)'); ?></div>
   
       			<span class="meta-data">
       				<?php the_category(); ?> &bull; <?php sp_authors_display(''); ?>
       			</span>
   
       		</div> <!-- end post-xy -->
   
       	</div> <!-- end col1 -->
   
       <?php endwhile; ?>
       ```
   
 * Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/post-enumeration/#post-1660534)
 * check how i do it in my blog:
    [http://www.transformationpowertools.com/wordpress/continuous-post-numbers](http://www.transformationpowertools.com/wordpress/continuous-post-numbers)
 * the oldest post will get the number 1; anytime you edit / add a new / or delete
   a post, the list will get updated.
    after you added the code to functions.php
   of your theme, you need at least to edit one post to initialize the list.
 * instead of
    `ENTRY NUMBER` you would need to use `<?php echo get_post_meta($post-
   >ID,'incr_number',true); ?>`
 *  Thread Starter [moarghorgh](https://wordpress.org/support/users/moarghorgh/)
 * (@moarghorgh)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/post-enumeration/#post-1660542)
 * That’s exactly what I was looking for! It works fine!
 * Just another question: I use the plugin _More types_ and your script doesn’t 
   work when I put the code `<?php query_posts('post_type=portfolio'); ?>` before
   the loop. Do you know how to change it that it works?
 *     ```
       <?php query_posts('post_type=portfolio'); ?>
   
       	<?php while ( have_posts() ) : the_post() ?>	
   
       		<div class="col1">
   
       			<div id="post-<?php the_ID(); ?>" class="entry">
   
       			<h2 class="entry-number">#<?php echo get_post_meta($post->ID,'incr_number',true); ?></h2>
   
       			<div class="entry-content"><?php the_content('(...)'); ?></a></div>
   
       			<span class="meta-data">
       				<?php the_category(); ?> &bull; <?php sp_authors_display(''); ?>
       			</span>
   
       		</div> <!-- end post-xy -->
   
       	</div>
   
       <?php endwhile; ?>
       ```
   
 * Thank you so much!
 *  Thread Starter [moarghorgh](https://wordpress.org/support/users/moarghorgh/)
 * (@moarghorgh)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/post-enumeration/#post-1660545)
 * Ah, I got it. Instead of _post_ here:
 * `$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status
   = 'publish' AND $wpdb->posts.post_type = 'post' ";`
 * I just have to write _portfolio_:
 * `$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status
   = 'publish' AND $wpdb->posts.post_type = 'portfolio' ";`
 * Thank you!
 *  [mattkaner](https://wordpress.org/support/users/mattkaner/)
 * (@mattkaner)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/post-enumeration/#post-1660810)
 * Hi.
 * I’m in a similar situation. I’m using custom post-types with WordPress 3.01. 
   Using moarghorgh’s solution I’ve changed the code that goes into functions.php
   and have managed to get the custom field working; the numbers adjust themselves
   automatically when I add/delete a new post.
 * However, I can’t for the life of me get the line of code below to work; and therefore
   can’t actually display the numbers!
 * `<?php echo get_post_meta($post->ID,'incr_number',true); ?>`
 * The custom post type is named ‘gallery’.
 *  [mattkaner](https://wordpress.org/support/users/mattkaner/)
 * (@mattkaner)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/post-enumeration/#post-1660811)
 * I seem to have found a way around this with `get_post_custom_values('incr_number');`
 * However, I’m still wondering, is there a way to reverse the enumeration i.e. 
   call the *newest* post 1, the next 2 etc.?

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Post enumeration’ is closed to new replies.

## Tags

 * [number](https://wordpress.org/support/topic-tag/number/)

 * 5 replies
 * 3 participants
 * Last reply from: [mattkaner](https://wordpress.org/support/users/mattkaner/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/post-enumeration/#post-1660811)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
