Support » Fixing WordPress » Different color for different date

  • Hi –

    I’ve been trying to figure this out all day. I’m not a coder so it might be a lot easier than I’m presenting it. Here goes.

    I have this code listing titles of pages with a certain parent.

      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
      <?php echo $children; ?>
      <?php } ?>

    What I really want to be able to do is evaluate the date the page was created and make the link red if it’s from this year. So far, all I’ve been able to do is add the year after the page title so someone can see when it was created. To draw attention to it, I wanted to make it red.

    I’ve tried to set $thisyear to date(‘Y’) and if it matches the_time(‘Y’), then use a certain style, but all it does is print a year (2008 in this case) at the very top of the list. Even when I’m not asking it to do that!

    I feel like I’m missing a while loop for it to know to keep going until the end of the pages, but am not sure where that would be placed, even.

    Has anyone any ideas to get me going in the right direction?


Viewing 3 replies - 1 through 3 (of 3 total)
  • I meant to add the link here, so you can see what I have:




    Forum Moderator

    if it matches the_time(‘Y’),

    try to match it against get_the_time('Y')

    Well, darn. I tried that, and here’s where the trouble is. It only seems to want to evaluate the very first page it hits and then stops.

    Maybe I’m not putting my ifs in the right place? I had to take out my attempts to keep their site going. 🙂

    Here’s the page, and here’s the code that was created for it.

    In My Opinion

    Template Name: In My Opinion
    <?php get_header(); ?>
    <div id="fullmain">
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <div class="post" id="post-<?php the_ID(); ?>">
    <!--	  <h2><?php the_title(); ?></h2>  -->
      <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    	  <?php endwhile; endif; ?>
    <!-- Here's where we want if posted in current year then make it red -->
      global $thisyear;
      $thisyear = date('Y');
      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&show_date=created&date_format=(Y)');
      if ($children)
    { ?>
      <?php echo $children; ?>
      <?php } ?>
    </div>  <!--close fullmain -->
    <br />
    </div>  <!--close content-->
    <br /><br />
    <?php include(TEMPLATEPATH."/subnav.php");?>
    </div> <!-- close wrapper -->
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Different color for different date’ is closed to new replies.