将唯一的 post 数字 ID 添加到 Wordpress posts
Adding a unique post number ID to Wordpress posts
我想在我的 Wordpress 网站上添加一个计数器。每个 post 都有一个 id,但它往往是一个很长的随机数。我想要每个 post 上的 1、2、3、4 ... 计数器,我可以在 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>
...
不知道从哪里开始完成这个
编辑
我的意思是第一个 post 会显示 1,第二个 post 会显示 2,等等。(post id 不会输出那样的简单数字)
我希望它输出如下所示
1 / post 标题
正文....
添加自定义字段并在该字段中输入您希望在标题附近显示的数字。
按照此处的文档操作: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>
我想在我的 Wordpress 网站上添加一个计数器。每个 post 都有一个 id,但它往往是一个很长的随机数。我想要每个 post 上的 1、2、3、4 ... 计数器,我可以在 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>
...
不知道从哪里开始完成这个
编辑
我的意思是第一个 post 会显示 1,第二个 post 会显示 2,等等。(post id 不会输出那样的简单数字)
我希望它输出如下所示
1 / post 标题
正文....
添加自定义字段并在该字段中输入您希望在标题附近显示的数字。
按照此处的文档操作: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>