What we had in mind was to show related nodes as images, not as titles, teasers or fullnodes. I added a view, to only show images, but it does not work. I pointed to this view, but it's still only possible to show full-nodes or teasers. Is it possible to get this to work using relatedcontent.tpl.php?

An example of a similar functionality to the related content module with images can be seen on the popular stockxpert site. See example on on http://www.sxc.hu/photo/924257 for related images below the main image.

Comments

TBarregren’s picture

Category: feature » support
Status: Active » Fixed

Since this can already be done with the RelatedCOntent module, I changed the category of this issue to support request.

You can accomplish this with the API provided by RelatedContent. Following pseudo code shows one way to accomplished what you want:

  if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
    $nodes = relatedcontent($nid);
    foreach($nodes as $node) {
      $image = $node->image;
      echo theme('image', $image);
    }
  }

Following pseudo code is a more "elegant" way to accomplish the same thing:


  if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
    $images = relatedcontent($nid, 'image_from_node');
    theme('images', $images);
  }

  function image_from_node($node) {
    return $node->image;
  }

  function theme_images($images) {
    foreach($images as $image) {
      $out .= theme('image', $image);
    }
  }

The benefit with the later version, except from being more "elegant", is that you now can override theme_images() in the template.php file, and make it, for instance, to read an images.tpl.php file.

Please notice that the above code snippets are only pseudo code and hence will not work without further development.

storbaek’s picture

I was suspecting that it was possible somehow :-)

I tested both snippets, but I'm unable to get them to work. I changed the 'image_from_node' to 'field_business_image', which is my machine readable fieldname and copied the snippet to my tpl.php file. I'm not sure if I'm supposted to change 'images' in theme('images', $images) or just leave it?
The snippet I used is:

  if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
    $images = relatedcontent($nid, 'field_business_image');
    theme('images', $images);
  }

  function field_business_image($node) {
    return $node->image;
  }

  function theme_images($images) {
    foreach($images as $image) {
      $out .= theme('image', $image);
    }
  }

The error I recieve on the page where the images of related content is:

warning: Illegal offset type in C:\xampp\htdocs\Drupal\modules\relatedcontent\relatedcontent.module on line 931.

Also, I'm using imagecache and I'm not sure if that can have something to do with it. I'm assuming that the pictures shown through these snippets will show me the pictures in full-size and not through imagecache, right?

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

littly_kitty’s picture

Status: Closed (fixed) » Active

Has anyone figured out how to use the pseudocode?

I think Related Content is an excellent module and being able to display just images (instead of teasers) would be a handy feature.

However, I am new to coding and so would greatly appreciate some pointers as how to change the pseudo code into working code.

(Apologies for changing the status to active, but I thought it would be a better thing to do than to start a new thread).