在Wordpress帖子中添加一个唯一的帖子编号
问题描述:
我想为我的Wordpress网站添加一个计数器。每篇文章都有一个ID,但它往往是一个很长的随机数字。我希望每个帖子上有一个1,2,3,4 ...可以在标题/段落旁显示。在Wordpress帖子中添加一个唯一的帖子编号
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内容单一
<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>
...
不知道从哪里开始实现这个
编辑
通过计数器我的意思是的第一个帖子会显示1,第二个帖子会显示2,等等(帖子ID不输出t等简单的数字)
我会把它想输出到如下所示
1 /文章标题
文本....
答
添加自定义字段,并输入在输入你想要在标题附近显示的数字。
按照文档在这里:https://codex.wordpress.org/Custom_Fields
你可以通过这个插件
https://wordpress.org/plugins/advanced-custom-fields/
添加自定义字段中的代码,以显示您的自定义字段将看起来像:
<h1><?php the_title(); ?> | <?php echo get_post_meta(get_the_ID(), 'my_custom_post_number,ber'); ?></h1>
莫非你更多地解释什么柜台应该准确计数?它从这个问题不清楚, – BenB