I used this code for a related content block (which I found in your handbook):

if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
  $host_node = node_load($nid);
  $grouped = relatedcontent_variable_output_grouped($host_node->type);
  if($groups = relatedcontent($host_node, $grouped)) {
    foreach($groups as $group => $nodes) {
      if ($nodes) {
        $links = array();
        foreach($nodes as $node) {
          $links[] = l($node->title, "node/$node->nid");
        }
        $title = relatedcontent_group_title($group, $grouped, $host_node->type);
        print theme('item_list', $links, $title);
      }
    }
  }
}

This works great...but it's not very visually stimulating. I would like to also like to display the first thumbnail from inside the image field inside this cck node. It's an imagecache field. Any suggestions?

And while we're at it, what's the best way to reference and display the other fields from inside the node inside this block?

Sorry, this is all probably very easy for you, but I'm not an experience php/drupal person.

Thanks in advance!

CommentFileSizeAuthor
#1 Screenshot-4.png177.34 KBpeter-boeren
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

peter-boeren’s picture

FileSize
177.34 KB

doubledoh,

thank you for your two questions. The first is not easy to explain but I will give it a try. Below is the example of the code resulting in a table with an image and a title. But it is also possible to put the values in divs and theme them yourself with css.

<?php
  if ((arg(0) == 'node') && is_numeric(arg(1))) {
    $nid = arg(1);
    $type_object = db_fetch_object(_relatedcontent_db_query('_relatedcontent_db_load_type', $nid));
    $nodes = _relatedcontent_db_load($nid);
    foreach ($nodes as $vid => $nids) {
      $vid = relatedcontent_view_title($vid, $type_object->type);

      // make a nice head of the table
      $header = array(array('data' => $vid,'colspan' => '2') );
      $rows = array();
      foreach ($nids as $nid => $value) {
        $title_object = db_fetch_object(_relatedcontent_db_query('_relatedcontent_db_load_title', $nid));
        $image_object = db_fetch_object(db_query('SELECT f.* FROM {content_type_page} as ctp JOIN {files} as f ON ctp.field_my_img_fid = f.fid WHERE ctp.nid = %d', $nid));
        $rows[] = array(theme('imagecache', 'thumb', $image_object->filepath, $image_object->filename, $image_object->filename), l($title_object->title, 'node/'. $nid));
      }
      $output .= theme('table', $header, $rows);
    }
  }
  return $output;
?>

In this code are a few assumption you will have to alter:

 1) $image_object = db_fetch_object(db_query('SELECT f.* FROM {content_type_page} as ctp JOIN {files} as f ON ctp.field_my_img_fid = f.fid WHERE ctp.nid = %d', $nid));

This code shows that I have added fields to the content type 'page' and the field is called 'my_img' and of the type 'image field'. This information is all in the database and you have to alter it to your needs. The only thing I want to achieve is to get file information from the files table that has been attached to the node.
2) theme('imagecache', 'thumb', $image_object->filepath, $image_object->filename, $image_object->filename)

Here I assume that there is an imagecache preset named 'thumb'. All option are:
<?php
print theme('imagecache', 'preset_namespace', $image_filepath, $alt, $title, $attributes);
?>

I hope this helps. Attached is a screenshot with the results, it is still not very stimulating but you can create your own theme function if you know how to gather the information.

Question 2: You have seen how to gather information from the database. Due to the fact that we have a node id, you can also use node_load($nid) to get all the fields of a node, but this has some negative influence on performance when using on large website (5000+ nodes).

peter-boeren’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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