Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As a visitor on a photo site I want a random photo uploaded in the recent week to be displayed in the sidebar. This is important since it helps me find photos I otherwise would have missed.
The functionality above can be achieved by the following steps:
- A node type for photos, containing images (such as the article node type).
- A new node view, with the name random image. In the quick-wizard, the block is checked (while page is left unchecked), and the block is set to display one result only.
- In the main configuration panel, a filter fields: field_image – fid ("file ID") is added to filter out nodes where the relevant image field is empty.
- Another filter content: post date is added, configured to only display nodes posted the most recent week.
- A new view field fields: field_image is added, displaying the content of the relevant image field in a style that fits the websites sidebar. The view field for node title, automatically added by the quick-wizard, is removed.
- The use pager is inspected, to assure that only one result is displayed, without any pager.
- A new sort criteria global: random replaces the one added by default, to allow selecting a random image.
- The view is saved, and the site's block settings are updated to display the new block in a suitable region.