Hi everyone,

I am wondering if there is a way to display node thumbnail in the similar entries block instead of Teaser?

Thank you

Comments

rmiddle’s picture

By default no but you can modify the .tpl.php file and make it happen pretty easily.

Thanks
Robert

Marat’s picture

Thank you very much for your replay.

I have changed this


  }
  if ($display_options == 'teaser') {
    foreach ($items as $node) {
      print '<li>'. l($node->title, 'node/'. $node->nid);
      print ' - '. $node->teaser;
      print "</li>\n";

to this


  }
  if ($display_options == 'teaser') {
    foreach ($items as $node) {
      print '<li>'. l($node->title, 'node/'. $node->nid);
      print ' - '. $node->field_thumbnail;       //replace teaser with field_thumbnail
      print "</li>\n";

but it does not work with me, any suggestions will be much appreciated.

rmiddle’s picture

Check out this link http://drupal.org/node/134086 . It might help it is for 5.1 but it might work. Also you might want for a test to print_r out the node list to confirm that $node->field_thumbnail exists.

Thanks
Robert

Marat’s picture

Status: Active » Postponed (maintainer needs more info)

Thanks Robert, I couldn't find the link on Check out this link. Could you please have a look?

rmiddle’s picture

That is weird it was there when I posted it reply. I updated to include the link and here it is again. http://drupal.org/node/134086

Thanks
Robert

Marat’s picture

Thank you very much @rmiddle, this is very helpful. I will try to make it through imagecache.

rmiddle’s picture

Status: Postponed (maintainer needs more info) » Fixed

No updated in over a month. This issue is outside the core design of the module. I am going to mark it fixed.

Militopedia’s picture

Hello,

I would also like to show thumbnails generated by imagecache instead of node titles.

Has anyone figured out how to do that with D6? I tried to use

$items_ls[] = l($node->field_squarethumbnail[0]['filepath'], 'node/'. $node->nid);

instead of

$items_ls[] = l($node->title, 'node/'. $node->nid);

in the similarterms.tpl.pho

but that didn't work.

Can anybody help?

Thanks!!

Roger

rmiddle’s picture

I though imagecache put it images in images/ not node/ are you certain the file it is looking for is in files/node/ ?

Thanks
Robert

Militopedia’s picture

Hi Robert,

I checked the path of a thumbnail. It is:

/sites/default/files/imagecache/squaretumbnail/"username"/

where "username" is the username of the node author.

Could you tell me how the code to print a thumbnail should look like? That would be great!

Cheers,
Roger

rmiddle’s picture

Do you have devel module installed on this site? Can you insert the following line.

      print '<li>'. l($node->title, 'node/'. $node->nid);
      print ' - '. $node->field_thumbnail;       //replace teaser with field_thumbnail
print_r($node);
      print "</li>\n";

and copy the large about of output this produces. That way I can see what is inside the array and figure out what you are getting.

Thanks
Robert

Militopedia’s picture

Hello Robert,

I don't have the devel module installed. But if that's something critical I should do in order for you to find out the correct code line I could install the module.

I added the code you indicated to similarterms.tpl.php. The output (the part that includes the thumbnail) is:

[field_albumimage] => Array ( [0] => Array ( [fid] => 192 [list] => 1 [data] => Array ( ) [uid] => 1 [filename] => flight helmet.jpg [filepath] => sites/default/files/album/1/flight helmet.jpg [filemime] => image/jpeg [filesize] => 148394 [status] => 1 [timestamp] => 1230459680 ) ) [path] => content/luftwaffe-flight-gear [simple_access_owner] => Array ( [sa_view] => 0 [sa_update] => 0 [sa_delete] => 0 ) [simple_access] => Array ( ) [tags] => [last_comment_timestamp] => 1230737055 [last_comment_name] => [comment_count] => 2 [taxonomy] => Array ( [67] => stdClass Object ( [tid] => 67 [vid] => 9 [name] => WWII 1939-45 [description] => [weight] => 5 ) [74] => stdClass Object ( [tid] => 74 [vid] => 10 [name] => Germany [description] => [weight] => 6 ) [89] => stdClass Object ( [tid] => 89 [vid] => 11 [name] => Air Force [description] => [weight] => 0 ) [134] => stdClass Object ( [tid] => 134 [vid] => 13 [name] => Flight Gear [description] => [weight] => 5 ) ) [files] => Array ( ) )

Does that help?

Thank you!

Roger

rmiddle’s picture

Try this code and let me know it output.

<?php
  }
  if ($display_options == 'teaser') {
    foreach ($items as $node) {
      $image = '<img src="'. $node->field_thumbnail[0][filepath] .'" alt="'. $node->title  . '" />';
      print '<li>'. l($image, 'node/'. $node->nid, 'html' => TRUE);
      print "</li>\n";
?>

Thanks
Robert

Militopedia’s picture

Hi Robert,

Thank you for the code.

I got a blank page when I added this code. Is there something wrong with the { or }? It looks to me as if one is missing.

Thanks
Roger

rmiddle’s picture

Roger,

Likely I haven't tested any of this code so a simple mistake like that is very doable. After looking at you previous code I made a new version that is less complicated and I think will do what you were tiring to get done.

<?php
  }
  if ($display_options == 'teaser') {
    foreach ($items as $node) {
      print '<li>'. l($node->title, 'node/'. $node->nid);
      print ' - '.'<img src="'. $node->field_thumbnail[0][filepath] .'" />' ;       //replace teaser with field_thumbnail
      print "</li>\n";
?>

Thanks
Robert

Militopedia’s picture

Hi Robert,

I tried to add the code but unfortunately it still didn't work. At least there wasn't a blank page anymore. But the '-' were followed by just an empty space. No pictures.

I tried to change the code from 'thumbnail' to 'squarethumbnail' (that's how I call the thumbnails in imagecache). But still no pictures.

I saw variations of [filepath] as ['filepath'] and tried this as well. But still no luck.

Could the problem be with the filepath. Do I have to change the filepath in Image Cache so that it shows correctly?

Thank you for your patience. I hope you can find a working solution as I am sure many other people would like to use this feature as well.

Thanks
Roger

Militopedia’s picture

PS: I checked the source code of the page and where the correct image path should be is:

Only local images are allowed.

So somehow the

"'. $node->field_thumbnail[0][filepath] .'"

doesn't work properly. I hope that helps.

Cheers,
Roger

rmiddle’s picture

Militopedia,

I pull $node->field_thumbnail[0][filepath] directly from the array you posted. Try this.

<?php
  }
  if ($display_options == 'teaser') {
    foreach ($items as $node) {
      print '<li>'. l($node->title, 'node/'. $node->nid);
//      print ' - '.'<img src="'. $node->field_thumbnail[0][filepath] .'" />' ;       //replace teaser with field_thumbnail
print $node->field_thumbnail[0][filepath];
      print "</li>\n";
?>

And confirm the output is the path to the file you want to display as an image.

Thanks
Robert

rmiddle’s picture

Status: Fixed » Postponed (maintainer needs more info)
Militopedia’s picture

Hello Robert,

I have tried but there was no output at all after the node titles. I tried several different variations (e.g. squarethumbnail instead of thumbnail, 'filename' instead of filename, different code, etc.) but no luck.

I have copied the source code of a views block that shows thumbnails of the latest added nodes. Perhaps this helps?:

Only local images are allowed.
<\code>

Apart from the code you have given me I tried the following:

$node['field_thumbnail'][0]['filename'] --> did not work, error

theme('imagecache', 'thumbnail', $node->field_thumbnail[0]['filepath']); --> no blank page, but no output

I am lost. What am I doing wrong?

Thanks,
Roger

rmiddle’s picture

OK replace print $node->field_thumbnail[0][filepath];

with

print_r($node->field_thumbnail[0][filepath]);
print_r($node->field_thumbnail[0]);
print_r($node->field_thumbnail);

Thanks
Robert

Militopedia’s picture

Hello Robert,

I tried it but there was no output whatsoever. I added an extra text print statement just to test if the changes to the file were successful. The text output was visible but unfortunately no output was generated by the 3 code lines you indicated. Where could be the mistake? What would you need more from me to tell what the problem is? I could send you the sitename via PM if you like (the site is not finished yet and I don't want to make it public yet).

Thanks,
Roger

Militopedia’s picture

PS: When I replace 'thumbnail' with albumimage (the name of the CCK field of which image assist generates a thumbnail called squarethumbnail) a path is given but to the original size image:

e.g.
http://sitename/sites/default/files/album/1/Bokelmann1.jpg

where the thumbnails are stored under
http://sitename/sites/default/files/imagecache/squaretumbnail/TestUser/1...

So it seems to me that the field 'thumbnail' is not recognized ?!

The original post (see below) didn't mention field_thumbnail but only field_albumimage (on first line). Are you sure that I should use field_thumbnail?

[field_albumimage] => Array ( [0] => Array ( [fid] => 192 [list] => 1 [data] => Array ( ) [uid] => 1 [filename] => flight helmet.jpg [filepath] => sites/default/files/album/1/flight helmet.jpg [filemime] => image/jpeg [filesize] => 148394 [status] => 1 [timestamp] => 1230459680 ) ) [path] => content/luftwaffe-flight-gear [simple_access_owner] => Array ( [sa_view] => 0 [sa_update] => 0 [sa_delete] => 0 ) [simple_access] => Array ( ) [tags] => [last_comment_timestamp] => 1230737055 [last_comment_name] => [comment_count] => 2 [taxonomy] => Array ( [67] => stdClass Object ( [tid] => 67 [vid] => 9 [name] => WWII 1939-45 [description] => [weight] => 5 ) [74] => stdClass Object ( [tid] => 74 [vid] => 10 [name] => Germany [description] => [weight] => 6 ) [89] => stdClass Object ( [tid] => 89 [vid] => 11 [name] => Air Force [description] => [weight] => 0 ) [134] => stdClass Object ( [tid] => 134 [vid] => 13 [name] => Flight Gear [description] => [weight] => 5 ) ) [files] => Array ( ) )

Thanks
Roger

Militopedia’s picture

I found the solution!!!!!!!!!!

The correct code is:

print theme('imagecache', 'squaretumbnail', $node->field_albumimage[0][filepath]);

So it was albumimage rather than thumbnail and I used the theme function.

But thank you for your time. Without your continuous support I wouldn't have tried it so far and would have given up. That saved my day. Now for a beer ;-)

Cheers,
Roger

Militopedia’s picture

Oh, I think I was too quick with the beer... :-( While the thumbnails are shown now, the problem is that always exactly the same 4 thumbnails are shown independent of the taxonomy of the current node. Even if the tags are completely different of the current node the same 4 thumbnails are shown.

HELP, I thought I did it.....

But the mistake could be my fault. I have 5 different vocabularies assigned to the node. None of them is a free tagging vocabulary and node of them is called 'Tags'. The help file of the module states that one should create a free tagging vocabulary called Tags.

Would it also be possible to use this module with the 5 non-free-tagging vocabularies instead? One is e.g. called period, one country, one branch of service, etc.

Thanks,
Roger

rmiddle’s picture

Sorry about that. I re-looked and you are right it should be $node->field_albumimage[0]['filepath'].

When all else fails print_r your data in this case $node->field_albumimage[0]['filepath'] and see what it outputs.

No I have zero tags called tags. And it no longer only creates blocks for free tagging taxo types. But the images you are garbing are not images for taxo terms but images related to the nodes themselves. So if you have an image attached to node/51 and node/51 is one of the items on the list it will give you a thumbnail of the image attached to node/51. Are you using taxo Image modules to attach images to taxo terms and you want to display images based on taxo terms used?

Thanks
Robert

Militopedia’s picture

Robert,

Thanks for the advice regarding the print_r. That's very good to know.

Regarding the tags I am confused. I thought that the module shows nodes that have most terms in common with the currently viewed at node? That's what I would like to achieve. Something like at youtube where you always get a suggestion of related videos (just pictures in my case) based either on terms or on the content itself.

I have the block 'Similar entries from ANY vocabulary.' activated. Shouldn't it show thumbnails of similar nodes that have tags in common with the currently looked at node?

I create one thumbnail per node. So every node just has one and instead of showing titles in the 'Similar entries...' block I would like to show these thumbnails instead. What did I do wrong that now always the same thumbnails are shown no matter at what node I am looking at?

Thanks,
Roger

Militopedia’s picture

Hi Robert,

I think it may actually work as expected. Since it is still a test site I don't have much content and I think that's the reason why always the same thumbnails were shown. I have added two nodes with tags I haven't used so far and the block indeed showed for both nodes the other node that has exactly the same tags :-) If so, I am sorry, my mistake, I should have checked the output more carefully before ringing the alarm bell.

Now all I have to add is adding a hyperlink to the thumbnails. Perhaps it's an easy task but I'll see. If I find out how to do it I will post it here.

Thanks!

Roger

Militopedia’s picture

Robert,

The following code generates a thumbnail with a hyperlink to the corresponding node. However, it doesn't use the imagecache thumbnail but scales the original image to 107x78. Hence, this is a very slow and resource intensive process.

print '<a href="/node/'. $node->nid.'"><img height="78" width="107" title="" alt="Similar posts" src="/'.$node->field_albumimage[0][filepath].'"></a>';

I tried a bit further and found the solution I was after:

print '<a href="/node/'. $node->nid.'"><img height="78" width="107" title="" alt="" '.theme('imagecache', 'squaretumbnail', $node->field_albumimage[0][filepath]).'</a>';

That may be something to consider as a new feature for your excellent module. Thanks for all your support!

Roger

rmiddle’s picture

Roger Maybe. I am more likely going to take the final solution and write it up in the document for a drop in replacement. The is lots of code I would have to add to allow this to work inside the man module.

Thanks
Robert

PS. Glad you were able to get what you wanted.

sunumen’s picture

Version: 6.x-1.9 » 5.x-1.15

Aftering reading your discussion, and checking out http://drupal.org/node/134086

I have worked out on my site which running 5.x1.15!!!

Here's how I concluded

1) I have a CCK image field called "pho"

2) I set a imagecache called "box"

3) In the similarterm module, add the codes into the function

function theme_similarterms($display_options, $items) {
$output = "";
if (!empty($items)) {
$output .= "

    \n";
    foreach ($items as $item) {
    $output .= '
  • '. l($item->title, 'node/'. $item->nid);
    if ($display_options == 'teaser') {
    $output .= ' - '. $item->teaser;

    // start adding these codes

    $nodep = node_load($item->nid);
    $output .= l($nodep->title, 'node/'.$nodep->nid);
    $output .= theme('imagecache', 'box', $nodep->field_pho[0]['filepath']);
    $output .= check_markup($nodep->teaser, $nodep->format, FALSE);
    $output .= '


    ';

    //end adding these codes

    }
    $output .= "

  • \n";
    }
    $output .= "

\n";
}
return $output;
}

rmiddle’s picture

Issue tags: +image display

sunumen,

Important note. I pass the full node to the theme function in 5 and the .tpl.php file in 6. There is no reason to reload the node info.

Thanks
Robert

rmiddle’s picture

Status: Postponed (maintainer needs more info) » Active

I am thinking about ways to use this I am just not seeing a way to use other then to add a document pages for people to use.

Thanks
Robert

iori57’s picture

The code below got mine working:
print theme('imagecache', 'BBBBB', $node->field_AAAAA[0]['filepath']);

it should be made clear that AAAAA is your CCK image field (NOT thumbnail) while BBBBB is your imagecache preset name :)

ressa’s picture

Thank you iori57, I could not make it work, but your tip got me started. This is what I ended up with, after selecting "Display Options: Display titles and teaser" under the "Similar By Terms" settings.

It tests for an image, and only prints if it exists. Replace from line 24 in similarterms.tpl.php with this:

  if ($display_options == 'teaser') {
    foreach ($items as $node) {
?>
<div class="views-row">
  <span class="views-field-field-illu-image-fid">
    <?php if ($node->field_illu_image[0]['filepath'] <> "") { ?>     
      <div class="field-content"><?php print theme('imagecache', 'small_thumbnail', $node->field_illu_image[0]['filepath']);?>
      </div>
    <?php }?>
  </span>
  <span class="views-field-title">
    <span class="field-content"><?php print l($node->title, 'node/'. $node->nid);?></span>
  </span>
</div>
<?php    
    }
  }
}
jjeff’s picture

Status: Active » Fixed

Similar By Terms 2 is a rewrite as a Views plug-in. Right now, it is only for Drupal 6 (and will likely not be backported to D5). But I wanted to post here because I know that displaying different information (such as thumbnails) in the block is something that many people have been interested in. As a Views plug-in, you can display whatever you want, however you want in the block... or on a page.. or in an RSS feed... whatever you want. And ImageCache support is built into Views.

Since the essence of the problem represented in this issue has now been addressed, I'm going to close out this issue. If someone wants to open another issue requesting better documentation of theming SBT1 in D5, that would be understandable.

ressa’s picture

Wow - just install, add an argument and sort by Similar Term. Very easy, thanks!
I wish had found SBT2 right away, then I wouldn't have had to hack the tpl.php and all that.

Status: Fixed » Closed (fixed)
Issue tags: -image display

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