Support » Fixing WordPress » Post List with gradually darkening color

  • Resolved zkemeny


    Here’s what I’m trying to do: I would like to have a list of the recent posts within a certain category listed in the sidebar, with a max length of 10. The tricky part is, I want the color of the entries to gradually get darker as it goes down, so the newest post title would be white, while the last one would be dark gray. This is the code I’m currently using. I can figure out how to alternate the colors, but just not how to increment the colors.


      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    • “><?php the_title() ?>
    • <?php endwhile; endif; ?>



Viewing 2 replies - 1 through 2 (of 2 total)
  • Always put code in backtick so it doesn’t get screwed up like that.

    Since the code you posted got screwy, I’ll just post some code of my own and you’ll have to figure out how to integrate it.

    Usually you accomplish this sort of thing with a simple incremental counter. Example:

    $i = 0; // start with whatever you want
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php $i++; // increase by 1 each time ?>

    And then as part of each <li> tag, use the $i to give it a numerical class. Something like this:

    <li class="title-<?php echo $i; ?>">

    And assign CSS styles for .title-0, title-1, and so on.

    Worked Perfectly!! thanks so much for providing this code, despite my mangled attempt to paste my own. 😉

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post List with gradually darkening color’ is closed to new replies.