0

How should I go about creating a view that only shows content that is older than the current node's creation date? I've created the argument using 'Content: created date' but I struggle to pass this over to the filter criteria.

To be honest, I'm not even sure this is the correct way to do it.

2
  • Looks like you have been struggling with this for a while now, Would you mind using some custom codes?
    – saadlulu
    Commented Jun 3, 2013 at 14:47
  • Hey saadlulu. I'll use anything as long as it works! Commented Jun 3, 2013 at 14:57

2 Answers 2

1

You'll need to create a block which accepts the node created date as an argument. Then you'll need to set the condition to only show nodes which have a created date < the argument value.

To pass on the node's created date as an argument, I think it's easiest just to embed the View block into the node's template using a PHP snippet. So you'll be looking at something along the lines of:

<?php print views_embed_view('my_view','my_block_machine_name', $node->created); ?>

You might have to check for the correct variable name for the created date of the node, but I think "created" is correct.

hope this helps!

1
  • Thanks AlexK. Managed to find a solution. Just posting now. Commented Jun 4, 2013 at 13:44
0

Managed to get this working with a Views PHP field:

<?php
global $base_path;

if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
  $node = node_load(arg(1));
  $a1 = format_date($node->created, 'custom', 'm/d/Y');
  $a2 = date("m/d/Y",strtotime("-2 months",strtotime($a1)));  
  $a3 = format_date($row->created, 'custom', 'm/d/Y');

  $b1 = new DateTime($a1);
  $b2 = new DateTime($a2);
  $b3 = new DateTime($a3);

  if ($b3 >= $b2 && $b3 <= $b1) {
    print '<h2><a href="'. $base_path . 'node/' . $row->nid . '">' . $row->title . '</a></h2>' . $data->field_body[0]['rendered']['#markup'];
    //dsm($data);
  }
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.