简体   繁体   中英

Adding a unique post number ID to Wordpress posts

I want to add a counter to my Wordpress website. Each post has an id, but it tends to be a long, random number. I want a 1, 2, 3, 4 ... counter on each post that I can show next to a title/paragraph.

HTML - single.php

get_header(); ?>

    <main role="main">

        <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content', 'single' ); ?>
        <?php bnNav_content_nav( 'nav-below' ); ?>

        <?php endwhile; // end of the loop. ?>

    </main>

<?php get_footer(); ?>

HTML content-single

<div id="post-<?php the_ID(); ?>" class="post-content"> 

  <div class="row post-text-wrap">

    <div class="counter"> *** counter number here ***  </div>       

      <h1><?php the_title(); ?></h1>

        ...

Not sure where to start to accomplish this

EDIT

By counter I mean the the first post would display 1, second post would display 2, etc. (The post id does not output simple numbers like that)

I would like it to output to look like the following

1 / post title

text ....

Add a custom fields and enter in that field the number you want to be displayed near the title.

Follow the docs here: https://codex.wordpress.org/Custom_Fields

You could add custom fields through this plugin

https://wordpress.org/plugins/advanced-custom-fields/

The code to display your custom field will look something like:

  <h1><?php the_title(); ?> | <?php echo get_post_meta( get_the_ID(), 'my_custom_post_number,ber' ); ?></h1>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM