How to enumerate a list of posts?

I’ve created a page with a list of posts from a specific category. I would like to enumerate this list like this:

  • lecture 1: post title 1
  • lecture 2: post title 2
  • lecture 3: post title 3
  • etc.

How can I do this?

Read More

Thanks

Related posts

Leave a Reply

3 comments

  1. I am not sure what your loop looks like from which you are adding the articles to your list. All you need do is to create a variable to hold your counter somewhere before the while statement in your loop. This could be something like

    <?php $counter = 0; ?>

    Note I am setting the counter to 0. Within the while statement you now enumerate this variable, this will keep on adding one to the counter for every time through the loop.

    <?php $counter++ ;?>

    Inside your loop you now use the variable to show the numbers you are interested in. This will give you a one on the first loop, two on the second etc.

    Hope this helps.

  2. I adapted my loop to be like the one proposed by RXN, so it is like this:

    <ul>
    <?php
    global $post;
    $args = array( 'category' => 3, 'offset'=> 1, 'numberposts' => -1, 'order' => asc, 'exclude' => '4307,4321');
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <div>
        <li class="paginaIndex-temario"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li></div>
    <?php endforeach; ?>
    </ul>
    

    and I introduced a list-style-type:decimal; in the stylesheed. Nevertheless I got a consecutive list of numbers for each post title everywhere but on Explorer (this give me a list of 1.,1.,1.,etc.) so I’m, at best, half way to success.

    Any thoughts? I would like to try whith the <?php $counter = 0; ?> but I really don’t know what to do with it.

    Thanks

  3. Here is what I found in the Codex. Simply replace the category number with the one you are using. I modified it with the counter you requested.

    <ul>
    <?php
    global $post;
    $args = array('category' => 6, 'offset' => 1, 'numberposts' => -1, 'order' => asc, 'exclude' => '4307,4321');
    $myposts = get_posts($args);
    $counter = 0;
    foreach ($myposts as $post) :  setup_postdata($post);
    ?>
        <div>
            <li class="paginaIndex-temario">Lesson # <?php echo $counter++;?> <a
                    href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        </div>
    <?php endforeach; ?>
    </ul>
    

    HTH