lundi 23 mars 2015

How can I display a number to represent the order of post?


I want to display the numerical number next to the_title of my WordPress posts. For example, I have 10 posts already:



  • 001 - First Post

  • 002 - Second Post ...

  • 010 - So on...


I have tried it with a a number that adds '1++' in every loop but what it displays is the opposite: First post = "010", Last post = "001".


here's my code. I want the reverse of this:



<?php
$query = new WP_Query( array(
'orderby' => 'ID',
'order' => 'DESC',
'post_type' => 'projects',
'posts_per_page' => -1
));

$start_value = 000;

if (have_posts()) : while ($query->have_posts()) : $query->the_post();
$terms = get_the_terms($post->ID, 'skill');

$start_value++;
$counter = sprintf("%03s",$start_value);

?>

<?php

echo $counter; include(locate_template('home/format.php'));
// displays as: 001 - This is the Last Post
endwhile; endif;
?>




Aucun commentaire:

Enregistrer un commentaire