Currently I have a basic View block just showing a bunch of articles in a teaser format. I added this view block to show up below the content of each article page. What I want is to be able to show the preceding articles in relation to the node you are currently viewing by the next future date.

The only extra thing in this view is that I added in contextual filters for NID. I am passing in multiple values into this view block, so YES i do have it "multiple values" checked off.

But I'm not sure why its not working. Technically it should be as it is in fact returning a string of NID's as outputted below:

if (arg(0) == 'node') {
  $node = menu_get_object();
$curNode = $node->nid;
$curNodeDate = $node->created;


$type = "article"; 
$nodes = node_load_multiple(array(), array('type' => $type)); 


$finalNid = array();

foreach($nodes as $products):
  if( intval($products->created) > intval($curNodeDate)  ){
dsm($products->created .'>'. $curNodeDate .'---'. $products->nid .'~~'. $products->title );
    $finalNid[] = $products->nid;

foreach($nodes as $products):
  if( intval($products->created) < intval($curNodeDate)  ){
dsm($products->created .'<'. $curNodeDate .'---'. $products->nid .'~~'. $products->title );
    $finalNid[] = $products->nid;

dsm(implode("," , $finalNid));

return implode("," , $finalNid);

When running that code I get the following dsm output:

1416508384>1416508382---65~~Rimmel's Georgia May Jagger & COTY partner with DBC
1416508383>1416508382---66~~Daisy Marc Jacobs Tweetshop Grabs the Attention of the Industry
1416508390>1416508382---68~~COTY's Mario Reis
1416508386>1416508382---71~~Beauty Trends for this Holiday Season
1416508385>1416508382---72~~COTY’s Catherine Walsh Honored
1416508388>1416508382---74~~ONE COTY - Looking at COTY as a Whole
1416508387>1416508382---75~~Roberto Cavalli
1416508389>1416508382---80~~A modern story of seduction
1416764226>1416508382---86~~Sir Ken Robinson
1416810455>1416508382---87~~COTY’s Svetlana Omelchenko makes the 2014 Top 100 OUTstanding LGBT Business Leaders List
1413318695<1416508382---2~~philosophy bringing hope & grace to mental health efforts
1413318711<1416508382---3~~Q&A with Ann Gottlieb
1413402303<1416508382---6~~Meet COTY CMO of Skincare
1416508381<1416508382---67~~Spotlight On Leadership: David Booth
1415666899<1416508382---73~~Creative Collaborations: COTY and Avon

1 Answer 1


$curnode = menu_get_object();
if (!$curnode) return '';

$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'article')
  ->propertyCondition('created', $curnode->created, '<=')
  ->propertyOrderBy('created', 'DESC')
  ->range(0, 10); //CHANGE RANGE FOR YOUR LIMITS

$result = $query->execute();

$items = array();
if (isset($result['node'])) {
  $nodes_nids = array_keys($result['node']);
  $nodes = entity_load('node', $nodes_nids);
  foreach ($nodes as $node) {
    $items[] = l($node->title, 'node/' . $node->nid);

return theme('item_list', array('items' => $items));

  • +1. If memory's a concern and if you don't need any field values, you could also directly query the node table to get the titles without loading the nodes
    – Andy
    Nov 27, 2014 at 11:47
  • This is odd. I got it working on views, but i had to create a completely new view using the same exact settings. Possibly a bug or some sort. I'd try to avoid doing custom code if it isn't necessary. Nov 29, 2014 at 0:46

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.