我在wordpress主题的index.php中有代码:
<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. Book Title: ..... Writer: ..... Publisher: ..... 4. Book Title: ..... Writer: ..... Publisher: ..... 3. Book Title: ..... Writer: ..... Publisher: ..... 2. Book Title: ..... Writer: ..... Publisher: ..... 1. Book Title: ..... Writer: ..... Publisher: .....
我应该添加什么代码并放在哪里?
答案 0 :(得分:1)
要拥有后代编号,首先需要获取总帖子数,然后在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>