• Does anyone know how to get the post number to show in the loop?
    Example:

    Post Title: “The Title”
    Date: “xx-xx-xxxx”
    Post Number: “4

    I want every post to have a number of which post it is.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • here is some code that automatically allocates a number to each post, starting with 1 for the oldest post, using custom fields:
    https://www.transformationpowertools.com/wordpress/continuous-post-numbers

    Thread Starter mr orange

    (@mr-orange)

    I am using the numbering system for my custom post loop (for a portfolio loop). Is there a ay to add the numbers to just that loop using custom post types?

    I can’t get the numbers to show up. I made a new post and still nothing. The only way the number shows up is if I manually add in a custom field for ‘incr_number’.

    Here is a look at my code:


    <?php include ('header-portfolio.php'); ?>

    <?php

    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    else { $paged = 1; }

    $myposts = array(
    'post_type' => 'portfolio',
    'posts_per_page' => '10',
    'orderby' => 'id',
    'order' => 'ASC',
    'paged'=> $paged
    );
    query_posts($myposts);
    ?>
    <?php posts_nav_link(' · ', 'previous page', 'next page'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="thumbwrapper">

    <div class="portfolio_post">

    <h2><a
    title="<?php the_title(); ?>"
    href="<?php the_permalink() ?>"
    rel="bookmark"><?php the_title(); ?><span><?php printf("%02d", get_post_meta($post->ID,'incr_number',true));?></span>

    </h2>
    <div class="portfolio_thumb">

    ">

    <?php the_post_thumbnail(); ?>

    </div>

    </div>

    </div>
    <?php endwhile; endif; ?>

    <div class="nav-previous"><?php next_posts_link( __( '« Older' ) ); ?></div>
    <div class="nav-next"><?php previous_posts_link( __( 'Newer »' ) ); ?></div>

    <?php wp_reset_query(); ?>

    i have no idea how to restrict/change this to custom post type posts.

    try and play with the post_type within this line in the code:

    $querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";

    generally, you need to echo the custom field value:

    echo get_post_meta($post->ID,'incr_number',true));?></span>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show the Post Number’ is closed to new replies.