ahs10 Posted May 2, 2007 Share Posted May 2, 2007 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 https://forums.phpfreaks.com/topic/49581-solved-change-color-of-link-by-age-of-post/ Share on other sites More sharing options...
btherl Posted May 2, 2007 Share Posted May 2, 2007 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 https://forums.phpfreaks.com/topic/49581-solved-change-color-of-link-by-age-of-post/#findComment-243092 Share on other sites More sharing options...
clown[NOR] Posted May 2, 2007 Share Posted May 2, 2007 maybe something like this <?php $post = the-post-date; $old = date("m-d-Y", strtotime("2 days ago")); if ($post <= $old) { // The post is 2 days old or older } else { //The post is less than 2 days old. } ?> Link to comment https://forums.phpfreaks.com/topic/49581-solved-change-color-of-link-by-age-of-post/#findComment-243097 Share on other sites More sharing options...
snowdog Posted May 2, 2007 Share Posted May 2, 2007 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 https://forums.phpfreaks.com/topic/49581-solved-change-color-of-link-by-age-of-post/#findComment-243099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.