Skip to content Skip to navigation
Tristan Stereo #2
Tristan Stereo #2, 2006
35mm stereoscopic photograph, photograph, digital animation from 35mm film.

Santcuary Stereo #27, 2006
digital animation from 35mm film, 35mm stereoscopic photograph, photograph.

Random Images from an Image Field in a Block in Drupal 7

The Problem:
Displaying a random image from the image field in a certain node type (where not every node has an image) in a block.

My Solution:
1. First thing is create a view with the following "Default" settings:

Creating a Page Template Suggestion for a Specific Node Type in Drupal 7

Add the following function to the template.php for your theme:

function yourthemename_preprocess_page(&$vars, $hook) {
 if (isset($vars['node'])) {
 // If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
  $vars['theme_hook_suggestions'][] = 'page__'.$vars['node']->type;

Change the "yourthemename" in the function name to match the name of your theme.


Subscribe to Front page feed Subscribe to Front page feed