This module effectively extends the functionality of a Views nid argument.

Please refer to Views Arguments Extras if you are considering this functionality for a project. Any future development that I will do will be to implement the same techniques into that project. See #852006: Same functionality in Views Arguments Extras for more information.

How it works

It provides a new Sort handler that means the View can be sorted in the same
order as the order of nids in the argument.

For example: http://example.com/my-view/9,1,4

If you have correctly configured a Views nid argument your query will be filtered
so that only nodes 9, 1 and 4 will display. By adding an Argument sort (ascending),
the nodes will be also ordered in this way. If you sort descending, then the nodes will be ordered 4, 1 then 9.

You might call this module something like "Node Queue lite" as it provides another way to arbitrarily order nodes in different situations.

Configuration

You need to add a node argument that allows for multiple nids to be passed into the view. Views Argument Sort is compatible with the format "3,5,4" or "3+5+4".

You then add a "Node: Argument sort" sort to the view. You can choose ascending or descending.

Suggest usage

Arbitrary path

Having created a view, you can add custom menu items to your site which will dictate the sort order of the nodes in that view. This provides a quick and dirty solution for customized sorting pages. Note that it is possible to do the same thing with Node Queue and Draggable Views - and these modules are recommended if you require a user interface for the custom sort options.

Render a View from code

Because you can pass arguments dynamically, this module enables you to ask Views for the output of a view customized with the nodes in the order that you request them on the argument.

  // Render nodes programmatically based on the saved nids. For example:
  // -- In a CCK formatter for a Node Reference field set to multiple values.
  // -- A Panels pane, where the nids are saved options.
  // -- A Boxes box, where the nids are saved options.
  $nids_argument = $this->options['nids'];
  $output = views_embed_view('my_view', 'default', $nids);
  return $output;

For the developer, the great thing about the example above is that you don't have to worry about the structure of the output, as this can be controlled through the Views interface. So the output in this example could be teasers, or some fields, or whatever. Once again, there is an API for Node Queue so as soon as your situation gets very complex you should check out that module.

Limitations

This code is alpha but would get a proper release if the following is resolved. They'll be added as issues to the queue.

  • No support yet for the "base_field" of other types of views: user views, file views, and so on.
  • MySQL support only. But this will be simple if PostgreSQL supports FIND_IN_SET().
  • It will probably break, or just fail, if you don't configure the nid argument properly.

Project Information

Downloads