I'm trying to setup a block to refresh in situ - but I think I may not be doing this right.

I want the block to show a new teaser for a story on refresh from a pool of the most recent 16 stories. But I'm a bit confused as to whether to do this I should do it in one or two blocks (one refreshing the other) - I want to avoid running the query on every refresh for performance reasons.

What I've done so far:

I've created a block, set it to be visible at the bottom of content on the appropriate page.

For the Dynamicload settings, I've skipped the first two settings ('Apply dynamic loading' and 'Target area') as I don't want it to refresh a different area. I've ticked 'Automatically refresh this block' and set 'Block refresh interval' to one minute.

In the block code

<?php
// Get the latest updated stories (cap at 16)
   $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.type = 'story' AND n.status = 1 ORDER BY n.created DESC"), 0, 16);

   $upper_limit = db_num_rows($result);

print "Starting - upper_limit=" . $upper_limit . "<br>";

   if ($upper_limit) {
      $row = rand(1,$upper_limit);
      $display_nid = db_result($result, $row);   // The nid of the block you want to display
      $display_node = node_load($display_nid);
      $output = node_view($display_node, $teaser = TRUE, $page = FALSE, $links = FALSE);
   
print "Id " . $display_nid . "<br>";
   return $output;
   }
?>

On page load it works beautifully - and I see the block, with its title and debug printing and teaser view of the selected story.

One minute later, the block refreshes - and becomes empty - no title, no content - nothing.

Can anyone point me in the right direction please? Feels like I'm so close!

Comments

csc4’s picture

Can no-one tell me why it blanks on refresh rather than loading the next node?

Please?

csc4’s picture

Category: support » bug

Bump - I'm thinking this must be a bug.

csc4’s picture

I could really use some help please - has no-one done anything similar? Is it a bug or is the problem with my implementation?