2013-04-14 40 views
0

我有這個UI與一些由WordPress生成的Li。 如果我使用<?php the_ID(); ?>它會全部搞砸,帖子ID不是按順序排列的。 我需要做的是讓jquery計數,並在我的卑微列表中寫入數字1,2,3和4。
這是我的UI
循環將得到4個職位,因此,4 <li>'s用Jquery計算和枚舉LI的

<div id="controle"> 
    <ul> 
<?php 
while ($loop->have_posts()) : $loop->the_post(); 
?> 

    <li> 
<a href="<?php the_ID(); ?>">1 <--! see? here is where the count goes :D --> </a> 
    </li> 

<?php endwhile; ?> 
    </ul> 
     </div> 

我想的東西用

$('#controle li').each(function(e){ 

} 

會做的伎倆,但不知道如何在此進行:(

謝謝大家!

回答

0

使用您each環,each回調的第一個參數是index

$('#controle li a').each(function(index){ 
    $(this).prepend('<span class="myNumberClass">'+ (index+1) +'</span>') 
}) 
+0

與一個$( '#CONTROLE李一')。每個(函數(指數)的完美,謝謝 – user1576978

+0

也可以在php中使用遞增計數器在'while'循環中非常簡單地執行此操作 – charlietfl

+0

這是我試過的,但我相信WP循環不會大聲說出來。 $ i ++只是沒有說出來 – user1576978

0

試試這個:

$("#controle li").each(function(index) { 
    $(this).find("a").text(index + 1); 
}); 

DEMO HERE