So I would like to add icon next to the story titles.

Form example – NEW! for the first 2 days after it has been promoted to the front page, that ACTIVE for the time the story is relevant (with possibility to set the expiration date somewhere), the EXPIRING SOON! last 2 days before expiry, then GONE after that date passes, and optionally removed from the front page.

What would be the most natural, easy, "drupal" way to do this?

Comments

nevets’s picture

It depends on what you mean by "expire", if you mean they become unpublished you could use the scheduler module for that part.

As for the icon part consider most themes place the node and it's content in a div and that div already has a id and a variety of classes. So you could add the following logic to the start of node.tpl.php (or node-story.tpl.php if it only applies to content of type story). Better yet would be to implement a preprocess function to set a variable for the class. Either way you would need code some like (this is a mix of PHP and psuedo code, it assumes it has $node available.

// Set the default state class based on if the node is published or not
$state_class = ( $status ? 'node-active' ? 'node-unpublished' );
// Now set time dependent state (only for published nodes
if ( $status ) {
  $two_days = ( 2 * 24 * 60 * 60 );
  $created = $node->created;
  $now = time();
  $expires = // Value depends on how you handle expiring content
  if ( ( $now - $created  ) < $two_days ) {
    $state_class = "node-new";
  }
  else if ( ( $expires - $now ) > 0 && ( $expires - $now ) < $two_days ) {
    $state_class = "node-expiring";
  }
}

Then for example using the garland theme you would change this line in node.tpl.php (or node-page.tpl.php from

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">

to

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php  " $state_class"; ?>">

Then you can use css to add a non-repeating background image to the node based on the state class.

sniegs’s picture

Thanks a lot, exactly what I was looking for!

Sorry for the time it took you, I would have hacked the code myself, the hard part was knowing in which places to plug it in drupal data model / file hierarchy.

Yes, by «expiring» I meant removing from the front page.

MiraKimura’s picture

Not a php programmer. Don't have a clue..

Anyway, is there any module i can use to have the icon "NEW" for new story as requested earlier? Need 1 >_<