I'm struggling to achieve something in Views that would be quite simple in PHP itself - hoping for some pointers.
I have created a view, displayed as a block, which appears at the bottom of each page with a content type of 'article'. This block shows the latest 4 articles added to the site based on publish date. It shows max 4 items (provided at least 4 articles exist and are published).
This works - however I've been struggling to extend this functionality to meet two new client requests:
- The view should exclude the currently viewed article if loaded on the page of one of the 4 latest articles added; [SOLVED THANKS TO ANSWER BELOW]
- The client wishes to 'override' the items shown in this view in some cases. Here I've added a field to the content type named 'field_related_articles' which is a entity reference field. The admin can now select up to 4 articles from the database which should show in this view. However it is optional, and the default behaviour is to show the 4 latest articles still. If 1 article is specified the 3 latest articles should then appear. If 2 then those 2 plus the latest 2 articles make up the view.
I've been advised to have two views then use an 'attached' display to stitch them together, then remove the extra results (if applicable) in code in a template file. But I'm struggling settling this up.
---------- EDIT : to add some clarity to second point ----------
The view is intended to always show 4 article teasers. In it's default state this should be the latest 4 articles added to the site. This is now working.
The complexity comes in that on each 'article' content page it should also be possible to specify up to 4 articles (using an entity reference field) to show in this view instead. I've added the field to the content type 'field_related_articles'.
So when the view is included on an article page it needs to check if any values are specified in 'field_related_articles' - if so they should be the results in the view. If less than 4 nodes have been specified, the view should then show the latest X articles to make up to 4 in total.