• 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)
  • check how i do it in my blog:
    https://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

    (@moarghorgh)

    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

    (@moarghorgh)

    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!

    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’.

    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.