Ready to get started?Download WordPress


Need to distinguish LI's independently from wp_get_archives (6 posts)

  1. Chuck Reynolds
    Posted 7 years ago #

    Currently I'm displaying the top 5 recent posts on my static home page with this...

    <?php wp_get_archives('type=postbypost&limit=5'); ?>

    I want to style each LI independently so that the most recent post is the largest and the next is smaller and the next smaller than that etc. I have the styles done but I need to know how to tell WP to add a class name to each LI with like a number or letter to decipher the first, second, third, etc...

    So the output I'd want something like this:

    <li class="recent1">link 1</li>
    <li class="recent2">link 2</li>
    <li class="recent3">link 3</li>
    <li class="recent4">link 4</li>
    <li class="recent5">link 5</li>

    Thank you in advance.

  2. Andrew Ozz
    WordPress Dev
    Posted 7 years ago #

    I don't think wp_get_archives() could do that. Perhaps try get_posts() followed by foreach() with an increment.

  3. Doodlebee
    Posted 7 years ago #

    You could try to take a look at the Fold Page List plugin. It's got some code in there that you could use do do what you wanted to. (I've done this very thing before - I needed each LI to have a class, as well, so I borrowed the fold page list plugin and edited it a bit for my needs. Worked fine!)

  4. Chuck Reynolds
    Posted 7 years ago #

    I'm not getting how to do the incremental class names with get_posts()

    I'm trying to run this within a page post with runPHP also.

    Any help azaozz? or anybody else?

    Wish I could find a site with that I'm trying to do for an example...

  5. Andrew Ozz
    WordPress Dev
    Posted 7 years ago #

    Try something like this in your theme's sidebar.php:

     $myposts = get_posts('numberposts=5');
     foreach($myposts as $key => $post) {
        <li class="recent<?php echo $key; ?>"><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li>
     <?php } ?>
  6. Chuck Reynolds
    Posted 7 years ago #

    score... that seems to work fine and dandy...

    thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic