1

I have two views on the frontpage, first one is a gallery and it should show only articles which have "promoted to frontpage" checked. The second view should show all the articles except the ones show in the first view.

I saw this question, but the answer does not help me, because in the second view, i don't want to exclude the "promoted to frontpage" articles, i just want to exclude the first 6 of them, all the other should appear mixed up with the other articles.

I also found this question, but as i use panels, i think it's not working for me.

How can i pass varibales from one view to another, or how to setup conditions to work like that? Or how can i set up more complex filters in a view, like

(promoted_to_frontpage== 1 && offset == 6) || (promoted_to_frontpage == 0)

2 Answers 2

1

If your views are not using pager then its easy just add a contextual filter with the following php code

$offset = 5

However, it is very unlikely. The best path is to use hook_views_pre_view($view)

Something like this

function YOUR-MODULE-NAME-HERE_views_pre_view($view, &$items) // note the '&' here!
{
  global $pager_page_array;

  // if this is our view...
  if ($views->name == "my-view-name" 
       // ..and we're on its first page...
       && $pager_page_array[0] == 0 ) {
    $items = array_splice($items, 0, 5); // ...then eat up the first 5 nodes
  }
}
3
  • but what happens on the second page?
    – sinini
    Commented Dec 16, 2015 at 16:43
  • if you are using pager, then you should use the second snippet
    – Shabir A.
    Commented Dec 16, 2015 at 19:22
  • Thanks for your help, in the end, i solved it with the PHP-Code in the contextual filter
    – sinini
    Commented Dec 19, 2015 at 10:32
1

Ok in the end, i was able to handle it with the answer of the maclean, which allowed me to configure everything in the views itself:

I have got two different views, not different displays, so in the first view, my gallery, i ad the Content:nid to the available fields and set it to not visible.

In the second view, i use - as he described - the contextual filter content:nid.

enter image description here

Provide default value, enter the code and - also as he described - Under "More" check both "Allow multiple values" and "Exclude".

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.