Hi,

I have 2 views:
1. View list all term nodes by date.
2. View where shows top viewed nodes (2 node only).

How can I exclude nodes from view #1 which is already in the view #2?
how can I display view #2 only if pager equal first page?

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcdonohue’s picture

For your first question "How to exclude already displayed nodes", perhaps the module Views Exclude Previous can help?

I'm looking for something similar. I have a featured node that appears via nodequeue, and then a view showing the 5 most recent postings. I want the featured node to be excluded from the list of recent postings.

Patrick

konrad1811’s picture

The same question...

having 2 views results - just titles of nodes that may be the same

I must exclude the second from first ones

I tried Views Exclude - but don't work from within minipanel :/

best if possible to join one view querry with another and take onliy distinguish nodes titles....

merlinofchaos’s picture

Status: Active » Fixed

Views doesn't really support this in any way that you can automate, so no matter what you're going to have to do a little bit of coding to glue this together.

The best thing you can do, I think, is to take all the nids from the view that must be excluded, concat them all together with + signs (so you get '1+2+3+4+5+6') and pass them to the second view as an argument.

The second view would then implement the Node: Nid argument and check the box for "exclude" as well as checking the box that allows it to accept + signs.

You could also run the first view in the argument default (or validate) code of the view.

merlinofchaos’s picture

Title: How to exclude nodes from view by another view? » Write tutorial explaining how to exclude nodes from view by another view?
Component: Miscellaneous » Documentation
Category: support » task
Status: Fixed » Active

This is probably a good candidate for a tutorial somewhere. Re-opening as a document task.

esmerel’s picture

Assigned: Unassigned » esmerel
iamjon’s picture

Ok, this is what I did:
In my example I had a view that pulled the titles from nodes from page, I wanted to exclude all the pages that have been marked as sticky at the top of lists.
You need to have two separate views, one that pulls that the entire data, and one that pulls the elements you want to exclude.
I have a view called views_exclude that pulls title and nid from page.
I have a view called views_excluder that pulls nid from page that have been filtered to bring the nodes that are sticky at the top of list.
In views exclude I added an node:nid as an argument Under Action to take if argument is not present->PHP Code

///grab results from views
$results = views_get_view_result('view_excluder', $display_id = NULL);
//make sure you have results
//if you have results
if(!empty($results)){
//create an empty array that will hold our nids
$willbestring= array();
//iterate over results and fill in the array
foreach($results as $key => $value) {
     $string[] = $value->nid;
}
//create a string that contains the nids seperated by a plus
$string = implode("+", $willbestring);
}
//if you don't have results declare a default value in our case '5+6'
else{
$string = "5+6"; //insert your default value instead of 4
}

return $string;

Insert that code into the view and presto it works.

iamjon’s picture

Updating the images
Assiging this to myself so I can remember to write up a patch.

iamjon’s picture

Assigned: esmerel » iamjon
iamjon’s picture

FileSize
9.84 KB

Ok. Here is my patch of the first draft. I will review it again because I think it needs tlc. I started off by using the author example as a base. It goes into great detail, and walks the user step by step. I tried to imitate this (blatently copy) but half way through I realized well if someone wants to do this they probably already know what an argument is...Maybe I was just being lazy. In either case I would love

I would love some input on whether or not I should go over it and continue in the beginner language style, or maybe I should change the entire entry to be more advanced centric.

iamjon’s picture

Version: 6.x-2.8 » 6.x-3.x-dev
Status: Active » Needs review
achton’s picture

I don't know if this is of any help at all, but for our purposes, we simply used "sticky" to discern if nodes were to be excluded or not. Editors can then choose which nodes appear in each view by setting them sticky. Works splendid in a media/newspaper environment.
Just jotting this down here, because sometimes simple solutions work too (though arguably not for everyone).

merlinofchaos’s picture

Assigned: iamjon » esmerel

Assigning to esmerel to review this.

esmerel’s picture

Still needs a grammatical review, etc, but this patch updates the ini file so that the help doc can be reached via the adv help interface.

esmerel’s picture

Status: Needs review » Needs work

Changing back to needs work because it does need a little :D

esmerel’s picture

Ok, I got as far as step 7 under "Cloning the view"

Scroll down to the Defaults: Rearrange filters click the gear icon on the on the same line as Node: Sticky Yes to remove the filter

Problem here being that this filter has not yet been added. Should it be up in the first view? :)

esmerel’s picture

added base_url to links

iamjon’s picture

Thanks esmerel, I'll give it's a read over for grammar.

esmerel’s picture

Assigned: esmerel » iamjon
clintthayer’s picture

subscribe

candelas’s picture

subscribe :)
thanks for the module!

leelooch’s picture

Thank you for this tutorial, it was a great help for me. However I had to correct two little things in the php argument code of view_exclude, witch may seem obvious but it would certainly make the life of the tutorial readers easier if we correct them : in line 9, replace $dude by $results and in the next line, $string by $willbestring so it becomes :

foreach($results as $key => $value) {
     $willbestring[] = $value->nid;
}

I can confirm that the view works well after applying these changes. Thanks again !

supradhan’s picture

Will this solution work on Drupal 7

Chris Matthews’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

The Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue