Can somebody help me to create a custom View Block showing 5 nodes before current node date.
example:

Lets say that I write a node-story per day. Lets say that today is 02-11-2008. :)

If I navigate to an older node , let's say the node published on 12.12.2007 I wish to show in a block the last 5 nodes published before 12.12.2007.

If I navigate to another node, let's say the node published on 11.11.2007 I wish to show in the same block the last 5 nodes published before 11.11.2007.

Can someone give me some instructions?

Comments

archard’s picture

I'm not sure you can do that with views. You might want to consider using a php snippet for that.

idflorin’s picture

Some one said that I need to use "offset(1)" in Views Arguments. But I have searched more information and I didn't get a more detailed answer.

mooffie’s picture

'archard' mentioned that this can be done without views. See the 'snippets' section of the handbooks.

But, if you want to use Views:

Here you need to use a 'filter', not an 'argument'. (Two reasons: 1. arguments can't handle hours and minutes; 2. arguments aren't capable of 'lower than').

You first need to build a view with a filter that shows the last 5 nodes posted before '2007-09-17 07:45'. The date isn't importand, it's hardcoded.

If you passed this stage, which doesn't require programming, you move on to the next stage, which does require programming: in the 'argument handling code' write code that changes this hardcoded date to that of the node. I'm not interested enough right now to write and test and debug the code, but here are some pointers. Start with:

/// change '123' to the index of the filter.
$view->filter[123]['value'] = '2005-09-11 05:00';

If, and only if, that code has an effect, change it to something along of:

if (arg(0) == 'node' && ($node = node_load(arg(1))) {
  $threshold = $node->created;
  // todo: timezone adjustment needed?
  $view->filter[123]['value'] = '@'. $threshold;
}

Perhaps you can find similar receipts in Views 'snippets' section of the handbooks.

EDIT:

Now, after finishing writing the above, I'm not sure this plan worth the bother. We're eviscerating Views here. Thing whould be elegant, not ugly.

idflorin’s picture

I must give up to this idea . :( I think is too hard for me. In the 'snippets' section I couldn't find anything (I've looked gain and again and again for several weeks now and for nothing.
Still I thing It's a very good idea.

idflorin’s picture

I'm back with a new kilo of patience. I'm still very interested in this feature because it's like a holly grail for my site; will be a new SEO thing to help drupal.
I wrote something similar here
http://drupal.org/node/248416

archard’s picture

I could easily do this with a PHP snippet if you're interested.

archard’s picture

I went ahead and did it anyway, just for the exercise =P


if(arg(0) == 'node'){
   $nid = arg(1);
   $node = node_load($nid);

   $sql = "SELECT * FROM {node} WHERE type = 'story' AND created < $node->created AND status = 1 ORDER BY created DESC LIMIT 5";
   $result = db_query(db_rewrite_sql($sql));
   $list = array();
   while ($data = db_fetch_object($result)) {
      $list[] = l($data->title, 'node/'.$data->nid);
   }
   echo theme('item_list', $list);
}

idflorin’s picture

Thank you. !
Know the next step for me is to print the nodetitle(with link to node), a image (generated for an image field from story), and the body (or teaser). The ideal is to have al of these in some vars for me to play with them.
Look at my teaser:

<?php if (!$page) { ?>
<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
 <div class="node-story-front">
  <div class="story-content">
	<?php print $node->field_story_image[0]['view'] ?>
	
<?php /* sort taxonomy links by vocabulary 1 */
$terms1 = taxonomy_node_get_terms_by_vocabulary($node->nid, 1);
if ($terms1) {
  print '<h3>';
     foreach ($terms1 as $key => $term1) {
     $lterm1 = l($term1->name, 'taxonomy/term/'.$term1->tid, array('title' => $term1->name));
     // work this way too $lterm1 = l($term1->name, taxonomy_term_path($term->tid), array('title' => $term1->name));
     print $lterm1.' ';
     }
  print '</h3>';
}
?>
  <?php
  $textfront = sp_mb_clean_words($content);
  // print $textfront = frontpage_check_content($content); // works this way too
  //$textfront = check_markup($content, 1, false);
  if(strlen($textfront) > 125) { $textfront = substr($textfront, 0, 125)." ...";};
  ?>
  <p class="description"><?php print $textfront; ?></p>

  <?php if (($title != '') && ($page == 0)): ?>
  <?php $titlefront = $title; if(strlen($titlefront) > 45) { $titlefront = substr($titlefront, 0, 45)." ...";}; ?>
  <h2><a href="<?php print $node_url; ?>" title="<?php print $title; ?>"><?php print $titlefront; ?></a></h2>
  <?php endif; ?>  
  



  </div>
 </div>
</div>
<?php } elseif (arg(0) == 'node' && is_numeric(arg(1)) && ($nid != arg(1))) {?>.......
hubkei’s picture

Is there any way this can be done in Drupal6 with views2?

I have been looking to solve exact problem for a long time now, but can't find any solution.

If anybody could help, would be great.