Jump to content

[SOLVED] change color of link by age of post


ahs10

Recommended Posts

i have a simple message board that includes a date the post was made.  when the message board is displayed, it shows the title of the post as a link to the main article.  right now, the color of that link is determined by a css class.  i would like the color of the links to change, depending on their age.  for example, if the post is less than two days old, it the link would be a different color than the links to posts that are older than two days.

 

can someone lead me into the right direction on how to do this please?  i really don't have any idea of what to even search for to get me started.  code snippets or keywords to search by would be greatly appreciated.  thanks in advance!

Link to comment
Share on other sites

I would start by working out how to calculate the number of days between the post date and now.

 

These functions will help: http://sg.php.net/manual/en/ref.datetime.php

 

That's the messy part.. after that, you just need to decide on what color you want for how many days.  You might want to setup some colour settings in css for each age, so you can modify the colours for each age group by modifying your main css file.

Link to comment
Share on other sites

Something like this would work, Might be more efficient ways but this works for me.

 

Snowdog

<code>

$todays_date = date("Y-m-d");

$link_date = (pull from database);

 

$date = (strtotime($todays_date) - strtotime($link_date))/86400;

 

if($date >= "2")

{

echo("<Change colour of your link><link here><end link><end colour>");

}

else

{

  echo("<Keep colour of your link><link here><end link><end colour>");

}

</code>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.