Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Ok, I have a custom post type to store list of urls. I would like to print those urls with serial numbers. I used foreach loop.

foreach($urls as $url){
echo $url;   

I got n number of urls as output. But i want to print serial numbers in each url like 1,2,3 and so on. I don't want to use unordered list. Because i want to style my serial numbers too. So is there any way to print serial numbers?

share|improve this question
    
Do you need to guarantee the serial numbers are always the same for every URL, on every page load. Or is it just a serial number generated for that particular page load / query? –  Ryan Gibbons Jul 24 '11 at 1:00

1 Answer 1

up vote 0 down vote accepted

How about:

echo '<ul>';

$sn_count = 1;
foreach($urls as $url){
    echo '<li><span class="serial-number">'.$sn_count.'</span> '.$url .'</li>';
    $sn_count++;
}

echo '</ul>';

You can then style your serial numbers with the serial-number class.

share|improve this answer
    
+1 Hey bro, Thanks your code working perfectly. I think there is a little bug in your code. $sn_count = $sn_count + 1; –  Giri Jul 24 '11 at 10:11
    
Has it occured to you that lists can be output with numbers? Switch that list to an ordered list and you'll essentially have the same thing(without the need to use a counter). –  t31os Jul 28 '11 at 15:21
    
To me yes, but from what i understood he wants to style each number differently, also i posted $sn_count = $sn_count + 1; to help him understand the incrementing process . –  Bainternet Jul 28 '11 at 17:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.