Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By iancawthorne on
Is there a way to do a dynamic offset with views?
For example.
I have a view returning the following node id's:
1, 2, 3, 4, 5
If I'm viewing node 3, I would like the view (as a block on that page) to show nodes 3, 4, 5. Eg, the current node is first i the view and the ones before are not displayed.
This would be the same as putting 3 in the "offset" option, but it is not dynamic.
Comments
just got handed same problem
subscribing
subscribing
subscribing
I'm sure this is possible,
I'm sure this is possible, but you'll need a bit of custom PHP. Beyond my abilities, I'm afraid.
sub
sub
drupal 7 solution
function {hook}_views_pre_view(&$view, &$display_id = null , &$args = null) {
$pager = $view->display_handler->get_option('pager');
$pager['options']['offset'] = 3;
$view->display_handler->override_option('pager', $pager);
}
Thanks
Thanks @arielberg your piece of code was awesome.
As to me, I did set something else than 3, so as to remove double results between a view and its attachment (the view has the dynamic offset as below + a pager; the attachment has the same query as the view, with "Inherit pager : no"):