如何在列表标题内容中添加Desc编号


How Add Desc Numbering in List Title Content Wordpress?

我有代码在index.php在wordpress主题:

<div id="content">
   <?php if ( have_posts() ) : ?>
   <?php while ( have_posts() ) : the_post(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        Book Title: <span class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>. Writer: <?php the_tags(' '); ?>. Publisher: <?php the_category(', '); ?>. </span>
        </div>      
   <?php endwhile;  ?>
   <?php endif;?>
</div>

我想看看我的博客如下:

<>之前……5. 书名:.....作者:…出版者:……4. 书名:.....作者:…出版者:……3.书名:.....作者:…出版者:……2. 书名:.....作者:…出版者:……1. 书名:.....作者:…出版者:……之前

添加增量值

<div id="content">
     <?php if ( have_posts() ) : ?>
     <?php $i = 1; ?>
     <?php while ( have_posts() ) : the_post(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        Number: <?php echo $i++; ?>Book Title: <span class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>. Writer: <?php the_tags(' '); ?>. Publisher: <?php the_category(', '); ?>. </span>
        </div>      
   <?php endwhile;  ?>
   <?php endif;?>
</div>

要获得后代编号,首先需要获得总张贴数,然后在每次while循环中减去1。

<div id="content">
   <?php if ( have_posts() ) : $post_nr = $wp_query->post_count; ?>
   <?php while ( have_posts() ) : the_post(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <?php echo $post_nr--;?>. Book Title: <span class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>. Writer: <?php the_tags(' '); ?>. Publisher: <?php the_category(', '); ?>. </span>
        </div>      
   <?php endwhile;  ?>
   <?php endif;?>
</div>