自动编号 Wordpress Taxonomy Post Type Category Posts 前面加 0
Auto numbering Wordpress Taxonomy Post Type Category Posts with 0 ahead of it
我想在这样的内容旁边自动生成 Wordpress 分类帖子编号 。我该怎么做才能将前 9 个帖子设为 0?
您可以使用 sprintf 函数:http://php.net/manual/en/function.sprintf.php,在循环中传入 post 的 ID:
<?php
$num_padded = sprintf("%02d", $post->ID);
echo $num_padded;
?>
如果少于所需的字符数(在本例中为 2),这只会将零添加到开头。
找到了一个疯狂而简单的solution.Here是有循环的代码
<?php $counts = 1 ; ?>
<?php
$query = new WP_Query( array('post_type' => 'benefits', 'posts_per_page' => 1000 ) );
while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="">
<?php if($counts < = 9){
echo '0'.$counts;
}else{
echo $counts;
} ?>
</div>
<?php $counts++; endwhile; ?>
我想在这样的内容旁边自动生成 Wordpress 分类帖子编号
您可以使用 sprintf 函数:http://php.net/manual/en/function.sprintf.php,在循环中传入 post 的 ID:
<?php
$num_padded = sprintf("%02d", $post->ID);
echo $num_padded;
?>
如果少于所需的字符数(在本例中为 2),这只会将零添加到开头。
找到了一个疯狂而简单的solution.Here是有循环的代码
<?php $counts = 1 ; ?>
<?php
$query = new WP_Query( array('post_type' => 'benefits', 'posts_per_page' => 1000 ) );
while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="">
<?php if($counts < = 9){
echo '0'.$counts;
}else{
echo $counts;
} ?>
</div>
<?php $counts++; endwhile; ?>