0

I'm working on a online magazine in drupal. I have one content type called issue with one field, the title field. And I have a content type called article the default drupal content type with a node reference field linking to issue.

I first make an issue called 'issue 01'. Then I start making some articles linked to 'issue 1' via the node reference field.

Then I make a second issue called 'issue 02'. And make some articles to go with this issue.

Now I want to make a view to show on the homepage showing all articles of the last added issue so for 'issue 02'. And when I would add a new issue called 'issue 03' the home page should automatically show the articles from this issue.

I'm trying to make this work via the relationship option and the contextual filter option in Views, the relationship is made. And the view is showing all articles. Now I want it to be filtered to showing articles of the last issue only so I thought about using the contextual filter but I can't find out a way to get, for instance, the NID of the last added issue.

Any help is welcome! Thanks in advance.

0

Order by the date DESC and restrict the displayed items to 1 through your pager options.

Only display most recent

  • Okay, but this is not what I ment. I know these options. But my view at this moment outputs all articles of all issues and I want it to show all articles of the most recent issue. Can you help me with this? – Joost Jan 9 '15 at 19:53
  • Offhand without changing what you have you could do a hook_query_alter and add a condition for post date === MAX(post date). But you could also set up your view a little differently. Something like have a block (or page) to display your issues that only shows 1 and then an attachment that shares exposed and contextual filters, same idea as the glossary view example. – sareed Jan 9 '15 at 20:41
  • Iv'e had issues with the attachment actually reading the contextual filters when using a block but you might not need it this way. – sareed Jan 9 '15 at 20:43
  • Okay thanks, I don't really understand what you mean by the attachment. I tried itwith the PHP code option in the contextual filter. I just search the database for the last added issue and use this NID to filter the content. I got it to work now but I'm wondering if it's the right way to do it. – Joost Jan 10 '15 at 12:31
  • At the end of the 'Displays' list in your view there is an +Add button. One of the selections here is 'attachment'. You can use these by attaching them to other displays. They can help add functionality to your view. – sareed Jan 12 '15 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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