2015-08-27 13 views
0

我在index.php的代碼在wordpress主題:如何在列表標題內容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. 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

更改您的問題標題。你想要作者姓名還是更改訂單? –

+0

我想放標題前的號碼,號碼排序是desc。 –

+0

我已經添加了答案。如果這有幫助的投票。 –

回答

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

感謝您的回答。這對於ASC。 –

+0

暈[Mr.Ghulam Ali](http://stackoverflow.com/users/4035101/ghulam-ali),如果使用頁面導航,上面的代碼不起作用。你能分享另一種解決方案嗎謝謝。 –

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

你的回答很好。我的問題解決了。感謝xphan。 –

+0

暈[Mr.xphan](http://stackoverflow.com/users/5171359/xphan),我現在有問題。如果使用頁面分頁,此代碼不起作用。你能有另一種解決方案嗎?謝謝。 –

+0

我建議你打開一個單獨的線程來解決這個問題。也看看這個例子:https://wordpress.org/support/topic/how-to-count-posts-in-paginated-loop – xphan

相關問題