1

Looking to implement something that will loop through nodes in the system. I'm not looking for carousel functionality, but instead want to load/display full-page node content, wait, and then load/display the next node.

The end result should be kinda like a TV channel, presenting nodes of various content types on big TVs in the common areas of our building.

I've got some ideas for how to build this, but would like to ask if there is a module that already accomplishes something similar?

1
  • 1
    Since you can do exactly this with full display node views and flexslider or owl carousel, why wouldn't you?
    – Screenack
    Commented Sep 4, 2015 at 0:56

1 Answer 1

1

I tried to implement this feature and I had almost achieved it. To try-out, click any preview button in this page, you can see the content cycling through nodes.

I suppose you want to cycle through a list of nodes generated by a View.

Procedure:

I used Views navigation module to preserve the list of nodes generated in a View. It also preserves the order of those nodes in cache.

In script:

(function ($) {
  Drupal.behaviors.module = {
    attach: function (context, settings) {

      //Posts the current position of node and Views-navigation cache ID - on clicking 'next' button
      $("body", context).on("click", ".next", function() {
        var pos = $(this).attr('data-pos');
        var cid = $(this).attr('data-cid');
        $.ajax({
          type: 'POST',
          url: '/navigation',
          dataType: 'json',
          data: 'pos='+pos+'&cid='+cid+'&dir='+dir+'',
          success: DoWhateverWithNextNode
        });
      });

    },
  };
})(jQuery);

In module:

//Menu callback for 'navigation'
function get_next_node() {
  if($pos = $_POST['pos']) {
    module_load_include('inc', 'views_navigation', 'views_navigation');

    $result = views_navigation_get_result($_POST['cid']);
    $max_index = count($result) - 1;
    $pos = ($pos > $max_index) ? 0 : (($pos < 0) ? $max_index : $pos);

    if ($nid = $result[$pos]) {
      $next_node = node_load($nid);
      return drupal_json_output($next_node);
    }
  }
}

In DoWhateverWithNextNode(data), you are required to increment 'data-pos' for '.next' element by 1. So that you can cycle through nodes.

P.S. This code may not be a working version. I just provided you an overview of my implementation.

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.