3

Drupal 7 with relevant Modules: Views & Entity Reference

I have a view that simply shows the "Teaser" display type of two different Content Type records, we'll say they are Article and Page. This is built into a Views Page.

My Article CT has some simple fields that are shown.

My Page CT has a few fields, but also an Entity Reference field (unlimited entries). The Entity Reference field points to other Article nodes.

My View then, as expected, shows each record's Teaser display and of course when a Page record references another Article record, that Article's teaser is shown as part of the Page teaser.

This is great. The problem is, I do not want to show duplicate Article teasers. That means, if a Page references an Article, I don't want to show that same Article teaser as an individual listing.

Think of it like this, I have these Articles:

  1. Article 1
  2. Article 2
  3. Article 3

And I have these Pages:

  1. Page 4
  2. Page 5
  3. Page 6

Page 4 points -> at Article 1 and Article 2

Page 6 points -> at Article 2

TL;DR

Right now the view would show something like:

  • Article 1
  • Article 2
  • Page 4
    • Article 1
    • Article 2
  • Page 5
  • Page 6
    • Article 2
  • Article 3

What I want is this:

  • Page 4
    • Article 1
    • Article 2
  • Page 5
  • Page 6
    • Article 2
  • Article 3

Here's a Diagram: https://i.stack.imgur.com/2joEr.jpg

2
  • i also got the same problem before.
    – monymirza
    Dec 4, 2012 at 6:00
  • Check out the answer I posted to the question then, it's working well.
    – Chris
    Dec 4, 2012 at 14:24

3 Answers 3

1

My guess would be to use fields instead of teasers, first. Then, use filter to undisplay Articles that are nodereferenced by pages - you then would only have pages and unreferenced articles showing up.

You might be able to do that with the relationship entityreference - reverse, or with views PhP if it doesn't work.

2
  • I can't really make use of fields without going through a whole lot of pain, as mentioned previously: Unfortunately this isn't using fields due to the method by which the content has to be rendered (very differently when shown as a child), as it's handled in node-tpl files. But, this is on the right track. As I managed to solve it using a 2-way relationship that didn't exist without another module. My answer is posted...
    – Chris
    Dec 4, 2012 at 14:21
  • I see that ; that's right, you actually didn't need to use fields, as fields filtering still works with teaser display :) I'm glad I helped. Thx for noting best answer ! Dec 4, 2012 at 14:27
0
  • Go and edit your view
  • In Advanced » OTHER section by enabling Use aggregation: Yes
  • In FIELDS or FILTER CRITERIA section, select and apply Aggregation settings for which fields you want to group by or distinct.
1
  • Unfortunately this isn't using fields due to the method by which the content has to be rendered (very differently when shown as a child), as it's handled in node-tpl files.
    – Chris
    Dec 4, 2012 at 14:19
0

I ended up knocking this out by making use of the Corresponding Entity Reference module (CER). This creates a 2-way relationship that is sync'd between the parent<->child. Using that, I could simply filter all children which have a parent from the View.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.