• Resolved zkemeny

    (@zkemeny)


    Hi,
    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

      query_posts(‘cat=10’);
      ?>
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

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

    thanks!

    -z

Viewing 2 replies - 1 through 2 (of 2 total)
  • Adam Brown

    (@adamrbrown)

    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:

    <?php
    $i = 0; // start with whatever you want
    query_posts('cat=10');
    ?>
    <?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.

    Thread Starter zkemeny

    (@zkemeny)

    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.