PUSTAKAKORAN.COM
PUSTAKAKORAN.COM

Reputation: 477

How Add Desc Numbering in List Title Content Wordpress?

I have code in index.php at wordpress theme:

<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>

I want to look at my blog as follows :

........
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: ..... 

What code should I add and placed where ?

Upvotes: 0

Views: 47

Answers (2)

xphan
xphan

Reputation: 1058

To have descendant numbering, you first need to get the total post count and then subtract 1 in each pass of the while loop.

<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>

Upvotes: 1

Ghulam Ali
Ghulam Ali

Reputation: 357

Add increment value

<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>

Upvotes: 1

Related Questions