WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post List with gradually darkening color (3 posts)

  1. zkemeny
    Member
    Posted 6 years ago #

    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

  2. Adam Brown
    Member
    Posted 6 years ago #

    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.

  3. zkemeny
    Member
    Posted 6 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic